/src/main/java/com/electricalweb/modules/EmailValidator.java
Java | 22 lines | 16 code | 6 blank | 0 comment | 0 complexity | 8196e9329bee6b7d507ee309b3990b1a MD5 | raw file
- package com.electricalweb.modules;
- import javax.validation.ConstraintValidator;
- import javax.validation.ConstraintValidatorContext;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class EmailValidator implements ConstraintValidator<ValidEmail, String> {
- private static final Pattern VALID_EMAIL_ADDRESS_REGEX = Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
- @Override
- public void initialize(ValidEmail constraintAnnotation) {
- }
- @Override
- public boolean isValid(String email, ConstraintValidatorContext constraintValidatorContext) {
- Matcher matcher = VALID_EMAIL_ADDRESS_REGEX.matcher(email);
- return matcher.find();
- }
- }