8000 Label regex in date validator · symfony/symfony@ec09f7e · GitHub
[go: up one dir, main page]

Skip to content

Commit ec09f7e

Browse files
committed
Label regex in date validator
1 parent 7466148 commit ec09f7e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Symfony/Component/Validator/Constraints/DateValidator.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
class DateValidator extends ConstraintValidator
2323
{
24-
const PATTERN = '/^(\d{4})-(\d{2})-(\d{2})$/';
24+
const PATTERN = '/^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})$/';
2525

2626
/**
2727
* Checks whether a date is valid.
@@ -61,7 +61,11 @@ public function validate($value, Constraint $constraint)
6161
return;
6262
}
6363

64-
if (!self::checkDate($matches[1], $matches[2], $matches[3])) {
64+
if (!self::checkDate(
65+
$matches['year'] ?? $matches[1],
66+
$matches['month'] ?? $matches[2],
67+
$matches['day'] ?? $matches[3]
68+
)) {
6569
$this->context->buildViolation($constraint->message)
6670
->setParameter('{{ value }}', $this->formatValue($value))
6771
->setCode(Date::INVALID_DATE_ERROR)

0 commit comments

Comments
 (0)
0