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.
The easiest thing for me was to overwrite the property in my custom entity and change the settings for the assertion:
Don't forget the validation groups.
Heads up:
user.password.short
translation is in thevalidators
Domain of your bundle inYourBundle\Resources\translations\
.Example:
Don't know if this is version specific; I'm using symfony v2.8.3 and fosuser ~2.0@dev (a39d000).
In YML you would do it like this:
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.