All Downloads are FREE. Search and download functionalities are using the official Maven repository.

plus.jdk.validator.Phone Maven / Gradle / Ivy

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());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy