提交 | 用户 | 时间
|
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 |
} |