PageRenderTime 93ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/com/electricalweb/modules/EmailValidator.java

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