提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.framework.common.validation; |
H |
2 |
|
|
3 |
import cn.hutool.core.util.StrUtil; |
|
4 |
import com.iailab.framework.common.util.validation.ValidationUtils; |
|
5 |
|
|
6 |
import javax.validation.ConstraintValidator; |
|
7 |
import javax.validation.ConstraintValidatorContext; |
|
8 |
|
|
9 |
public class MobileValidator implements ConstraintValidator<Mobile, String> { |
|
10 |
|
|
11 |
@Override |
|
12 |
public void initialize(Mobile annotation) { |
|
13 |
} |
|
14 |
|
|
15 |
@Override |
|
16 |
public boolean isValid(String value, ConstraintValidatorContext context) { |
|
17 |
// 如果手机号为空,默认不校验,即校验通过 |
|
18 |
if (StrUtil.isEmpty(value)) { |
|
19 |
return true; |
|
20 |
} |
|
21 |
// 校验手机 |
|
22 |
return ValidationUtils.isMobile(value); |
|
23 |
} |
|
24 |
|
|
25 |
} |