In the FOUserBundle, I would like to be able to change the validation settings for minimum length, maximum length and not blank on fields such as username and password.
I was able to put some validation via @Assert
on my custom fields, but now I am wondering how I could change the username validation for the FOSUserBundle?
These fields are generated automatically, so I can't add them to my User
entity… and by default, it allows characters like {^|
etc… which don't look good.
Best Answer
You can overwrite the default settings by creating a new validation file in your bundle. This is bundle inheritance. Just copy (not cut).
FOSUserBundle/Resources/config/validation/orm.xml
toYourBundle/Resources/config/validation/orm.xml
.(
couchdb.xml
,mongodb.xml
,propel.xml
respectively)and adjust it to your needs. Change the class name, then add your constraints:
Read more about which constraints are available (and how to use them with xml configuration ) in the Validation Constraints Reference.