Reputation: 23587
I am trying to validate my form Data using Hibernate Validator in my Spring MVC application. I have a requirement where i need to check user input for predefined values which will not be allowed in the system.
for e.g if the value of firstName field is firstName, i want to fail the validation and tell user that this value is not allowed.
Can any one tell me how this can be achieved using hibernate validation
Upvotes: 0
Views: 3160
Reputation: 9914
You can create a custom validator that implements ConstraintValidator
.
Please read this link:
Hibernate validator
Upvotes: 3
Reputation: 4483
You can also use @Pattern
annotation on top of your field declaration. With this annotation you need to specify the java regex pattern that will match with the value input by user and if it fails you can show the proper validation message to the user in jsp.
Hope this helps you. Cheers.
Upvotes: 3