Concept Flow - @Email and @Pattern
Start: Input String
Apply @Email Validation
Apply @Pattern
Accept Input
The input string is first checked by @Email for email format. If valid, @Pattern applies regex rules. Only if both pass, input is accepted.
@Email
@Pattern(regexp = "^[a-zA-Z0-9._%+-]+@example\\.com$")
private String email;| Step | Validation Annotation | Input Value | Validation Result | Action |
|---|---|---|---|---|
| 1 | user@example.com | Valid | Proceed to @Pattern | |
| 2 | @Pattern | user@example.com | Matches pattern | Accept input |
| 3 | user@wrongdomain.com | Valid | Proceed to @Pattern | |
| 4 | @Pattern | user@wrongdomain.com | Does not match pattern | Reject input |
| 5 | invalid-email | Invalid | Reject input |
| Variable | Start | After Step 1 | After Step 2 | After Step 3 | After Step 4 | After Step 5 |
|---|---|---|---|---|---|---|
| null | "user@example.com" | "user@example.com" | "user@wrongdomain.com" | "user@wrongdomain.com" | "invalid-email" | |
| @Email Result | N/A | Valid | Valid | Valid | Valid | Invalid |
| @Pattern Result | N/A | N/A | Matches pattern | N/A | Does not match pattern | N/A |
| Final Validation | N/A | Pending | Accepted | Pending | Rejected | Rejected |
@Email checks if a string is a valid email format. @Pattern applies a regex to enforce specific rules. Both validations must pass for acceptance. Use @Email for general email format. Use @Pattern for custom domain or format rules.