Answer the question
In order to leave comments, you need to log in
How to add custom validation rules to FOSUserBundle username?
On the site for registration I use FOSUserBundle, only now it allows using any characters for username.
How to add a validator for username allowing only [a-b0-9] latin characters?
Answer the question
In order to leave comments, you need to log in
You can add the loadValidatorMetadata method to the User class.
My example of a nickname on a project (regex needs to be replaced with the required one):
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint(
'nickname',
new Regex(array(
'pattern' => '/^[a-yayoa -z0-9_\- ]+$/ui',
'groups' => array('Profile', 'forum'),
'message' => 'Nick must not contain %, !, ~, #, &, No.'
))
);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question