it.shifty.datamask.validate.ValidateInput Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of datamask Show documentation
Show all versions of datamask Show documentation
A library to pseudonymize data while keeping data format
The newest version!
package it.shifty.datamask.validate;
import javax.xml.bind.ValidationException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ValidateInput {
private static final Pattern VALID_EMAIL_ADDRESS_REGEX =
Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
public static void validateEmail(String emailStr) throws ValidationException {
Matcher matcher = VALID_EMAIL_ADDRESS_REGEX.matcher(emailStr);
if (!matcher.find())
throw new ValidationException(String.format("The input provided '{0}' does not seem a valid email", emailStr));
}
}