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