package com.qianwen.smartman.common.validator.phone;
|
|
import cn.hutool.core.util.StrUtil;
|
import javax.validation.ConstraintValidator;
|
import javax.validation.ConstraintValidatorContext;
|
|
public class PhoneValueValidator implements ConstraintValidator<PhoneValue, String> {
|
private Boolean required;
|
|
public void initialize(PhoneValue constraintAnnotation) {
|
this.required = Boolean.valueOf(constraintAnnotation.required());
|
}
|
|
public boolean isValid(String phoneValue, ConstraintValidatorContext context) {
|
if (!StrUtil.isEmpty(phoneValue)) {
|
return phoneValue.length() == 11;
|
} else if (this.required.booleanValue()) {
|
return false;
|
} else {
|
return true;
|
}
|
}
|
}
|