懒羊羊
2023-10-09 ffeba3afc3a78c0f479f500f3d68d5c6915c7851
1
2
3
4
5
6
7
8
9
10
11
12
13
14
package cn.stylefeng.guns.sys.core.validation;
 
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
 
public class PhoneNumberValidator implements ConstraintValidator<PhoneNumber, String> {
 
    @Override
    public boolean isValid(String phoneField, ConstraintValidatorContext context) {
        if (phoneField == null) return true; // can be null
        return phoneField != null && phoneField.matches("[0-9]+")
                && (phoneField.length() > 8) && (phoneField.length() < 14);
    }
}