Reputation: 267267
Is it possible to check a String against a hibernate constraint without having to write a special Class for it? For example, if I just want to check if a given String is an email, is it possible to check it as a one-off test without writing a full class and validating that constraint against a particular property of the class?
Upvotes: 5
Views: 3430
Reputation: 90
You can annotate the property with @Email in your entity class. You can read the documentation in this link: http://docs.jboss.org/ejb3/app-server/HibernateAnnotations/api/org/hibernate/validator/Email.html
Edited:
String email = "[email protected]";
EmailValidator validator = new EmailValidator();
validator.isValid(email, null);
The method "isValid" will return true if your string is a well-formed email address.
Hope it helps!
Upvotes: 6