Performance: @Email and @Pattern
These annotations affect form validation speed and user input responsiveness during server-side validation.
Jump into concepts and practice - no test required
@Email private String email;
@Pattern(regexp = ".*@[a-z]+\\.[a-z]{2,3}")
private String email;| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| @Email annotation | 0 | 0 | 0 | [OK] Good |
| Simple @Pattern regex | 0 | 0 | 0 | [!] OK |
| Complex @Pattern regex | 0 | 0 | 0 | [X] Bad |
@Email annotation in Spring Boot validation?@Email annotation is designed to validate that a string looks like a proper email address format.@Pattern is used for custom regex, @NotEmpty ensures non-empty, and no annotation converts case automatically.@Pattern to allow only digits in a Spring Boot entity field?@Pattern is regexp, not regex or pattern.\\d+ matches one or more digits. @Pattern(regexp = "\\d+") uses correct syntax and regex.@Email @Pattern(regexp = ".+@example\\.com$") private String email;
user@test.com?@Email @Pattern(regexp = "[a-zA-Z]+") private String userEmail;
[a-zA-Z]+ allows only letters, no digits, dots, or @ symbols which are common in emails.mycompany.com domain. Which annotation setup is correct?.+@mycompany\\.com$ ensures the email ends with '@mycompany.com'.