I need to do a validation of an e-mail using annotation + regex. I tried to use the following:
@NotNull
@Pattern(regexp=".+@.+\\.[a-z]+")
private String email;
However, I don’t know how to print an error message when I have an incorrect e-mail address in the email field. Any ideas?
First you should add a
messageattribute to yourPatternannotation.Assume that your mail variable is part of some class User:
Then you should define a validator:
Then find validation errors.