From ec09f7e630d8d0431c732ad11414e1298399ee3d Mon Sep 17 00:00:00 2001 From: Kristof Van Cauwenbergh Date: Fri, 29 Nov 2019 10:53:07 +0100 Subject: [PATCH] Label regex in date validator --- .../Component/Validator/Constraints/DateValidator.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Validator/Constraints/DateValidator.php b/src/Symfony/Component/Validator/Constraints/DateValidator.php index 9590827103..c098928e51 100644 --- a/src/Symfony/Component/Validator/Constraints/DateValidator.php +++ b/src/Symfony/Component/Validator/Constraints/DateValidator.php @@ -21,7 +21,7 @@ use Symfony\Component\Validator\Exception\UnexpectedValueException; */ 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 @@ class DateValidator extends ConstraintValidator 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)