diff --git a/backend/pom.xml b/backend/pom.xml index 0637d229be..e323a96730 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -92,11 +92,6 @@ org.apache.commons commons-lang3 - - commons-validator - commons-validator - 1.7 - org.apache.commons commons-text diff --git a/backend/src/main/java/ca/bc/gov/app/util/ClientValidationUtils.java b/backend/src/main/java/ca/bc/gov/app/util/ClientValidationUtils.java index 081858c013..b5d48570fd 100644 --- a/backend/src/main/java/ca/bc/gov/app/util/ClientValidationUtils.java +++ b/backend/src/main/java/ca/bc/gov/app/util/ClientValidationUtils.java @@ -2,17 +2,19 @@ import ca.bc.gov.app.dto.client.ClientTypeEnum; import ca.bc.gov.app.dto.client.LegalTypeEnum; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.apache.commons.lang3.EnumUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.validator.routines.EmailValidator; import org.springframework.validation.Errors; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class ClientValidationUtils { - private static final EmailValidator emailValidator = EmailValidator.getInstance(); + private static final String EMAIL_REGEX = "^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$"; + private static final Pattern EMAIL_PATTERN = Pattern.compile(EMAIL_REGEX); public static void validateEmail(String email, String field, Errors errors) { if (StringUtils.isBlank(email)) { @@ -20,9 +22,10 @@ public static void validateEmail(String email, String field, Errors errors) { return; } - if (!emailValidator.isValid(email)) { + Matcher emailMatcher = EMAIL_PATTERN.matcher(email); + if (!emailMatcher.matches()) { errors.rejectValue(field, "You must enter an email address in a valid format. " - + "For example: name@example.com"); + + "For example: name@example.com"); } }