Symfony Regex validator doesn't work in annotation Symfony Regex validator doesn't work in annotation symfony symfony

Symfony Regex validator doesn't work in annotation


It seems that for this specific regular expression, the one in the annotation should not escape \d bit, however in the PHP implementation (ie using loadValidatorMetadata) we need to escape it.

If I edit the model which implemented the constraint in annotation as follows, it works:

/** * @Assert\NotBlank(message="New password can not be blank.") * @Assert\Regex(pattern="/^(?=.*[a-z])(?=.*\d).{6,}$/i", message="New password is required to be minimum 6 chars in length and to include at least one letter and one number.") */private $newPassword;

Just edit /^(?=.*[a-z])(?=.*\\d).{6,}$/i to /^(?=.*[a-z])(?=.*\d).{6,}$/i

This seems to inconsistent. I think the annotation, yaml, xml and PHP implementations need to be identical whereas possible, the documentation should emphasize all of the inconsistencies.

Therefore I raised an issue on Symfony repo.