I'm using FOSUserBundle in my Symfony2 project. I can't find any sensible explanation how to override form fields validation. I need to set password field validation to at least 7 characters, at least one small letter, at least one capital letter and at least one digit. None of solutions I've found alreade seems to work. Any ideas?
Use a standard Regex
constraint with the following pattern /(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).{7,}/
class User extends FOSUser
{
/**
* @Assert\Regex(
* pattern="/(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).{7,}/",
* message="Password must be seven or more characters long and contain at least one digit, one upper- and one lowercase character."
* )
*/
protected $plainPassword;
}
you shoud create a custom constraint class like described in documentation
that should fit your needs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With