club.zhcs.lina.web.jsr380.validator.IDCardValidator Maven / Gradle / Ivy
The newest version!
package club.zhcs.lina.web.jsr380.validator;
import org.nutz.lang.Strings;
import club.zhcs.lina.web.jsr380.constraints.IDCard;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
/**
*
* @author Kerbores([email protected])
*
*/
public class IDCardValidator implements ConstraintValidator {
private boolean required = false;
@Override
public void initialize(IDCard anno) {
required = anno.required();
}
@Override
public boolean isValid(String idcard, ConstraintValidatorContext context) {
if (required) {
return Strings.isNotBlank(idcard) && ValidatorUtil.isIDCard(idcard);
} else {
// 允许为空
if (Strings.isBlank(idcard)) {
return true;
} else {
return ValidatorUtil.isIDCard(idcard);
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy