diff --git a/src/Symfony/Component/Validator/Constraints/DateValidator.php b/src/Symfony/Component/Validator/Constraints/DateValidator.php index 959082710390a..c098928e51bd6 100644 --- a/src/Symfony/Component/Validator/Constraints/DateValidator.php +++ b/src/Symfony/Component/Validator/Constraints/DateValidator.php @@ -21,7 +21,7 @@ */ class DateValidator extends ConstraintValidator { - const PATTERN = '/^(\d{4})-(\d{2})-(\d{2})$/'; + const PATTERN = '/^(?\d{4})-(?\d{2})-(?\d{2})$/'; /** * Checks whether a date is valid. @@ -61,7 +61,11 @@ public function validate($value, Constraint $constraint) return; } - if (!self::checkDate($matches[1], $matches[2], $matches[3])) { + if (!self::checkDate( + $matches['year'] ?? $matches[1], + $matches['month'] ?? $matches[2], + $matches['day'] ?? $matches[3] + )) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) ->setCode(Date::INVALID_DATE_ERROR)