Label regex in date validator
This commit is contained in:
parent
746614807a
commit
ec09f7e630
@ -21,7 +21,7 @@ use Symfony\Component\Validator\Exception\UnexpectedValueException;
|
||||
*/
|
||||
class DateValidator extends ConstraintValidator
|
||||
{
|
||||
const PATTERN = '/^(\d{4})-(\d{2})-(\d{2})$/';
|
||||
const PATTERN = '/^(?<year>\d{4})-(?<month>\d{2})-(?<day>\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)
|
||||
|
Reference in New Issue
Block a user