io.afu.validator.Implement.ChineseWordValidatorImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of validator Show documentation
Show all versions of validator Show documentation
RffanLAB Validator For Many Way use
package io.afu.validator.Implement;
import io.afu.validator.Annimation.ChineseIdCard;
import io.afu.validator.Annimation.ChineseWord;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ChineseWordValidatorImpl implements ConstraintValidator {
private Boolean allowEmpty;
@Override
public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
if (null == s || s.equals("")){
return this.allowEmpty;
}else {
String regex = "[\\u4e00-\\u9fa5]";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(s);
return m.find();
}
}
@Override
public void initialize(ChineseWord constraintAnnotation) {
this.allowEmpty = constraintAnnotation.allowEmpty();
}
}