plus.jdk.validator.Phone Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of validator-plus Show documentation
Show all versions of validator-plus Show documentation
A simple input parameter verification component
The newest version!
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.Matcher;
import java.util.regex.Pattern;
public class Phone implements IValidator {
@Override
public void validate(ValidationRule validationRule, String fieldName, Object fieldValue, Field field, Object input, Object args) throws ValidateException {
Pattern p = Pattern.compile("^1\\d{10}$");
Matcher m = p.matcher(String.valueOf(fieldValue));
if (!m.matches()) {
throw new ValidateException(validationRule.message());
}
}
}