![JAR search and dependency download from the Maven repository](/logo.png)
plus.jdk.validator.Email Maven / Gradle / Ivy
package plus.jdk.validator;
import plus.jdk.ananotaions.ValidationRule;
import plus.jdk.common.IValidator;
import plus.jdk.common.ValidateException;
import java.lang.reflect.Field;
import java.util.regex.Pattern;
public class Email implements IValidator {
@Override
public void validate(ValidationRule validationRule, String fieldName, Object fieldValue, Field field, Object input, Object args) throws ValidateException {
if (fieldValue == null) {
throw new ValidateException(validationRule.message());
}
String value = String.valueOf(fieldValue);
String regEx = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
if(!args.equals("")) {
regEx = String.format("^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@(%s)$", args);
}
Pattern p = Pattern.compile(regEx);
if(!p.matcher(value).matches()) {
throw new ValidateException(validationRule.message());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy