shikeyin
2024-01-11 65da8373531677b1c37a98f53eaa30c892f35e5a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package com.iplatform.base.util;
 
import com.iplatform.base.PlatformRuntimeException;
import com.iplatform.core.RegularConstants;
import com.walker.infrastructure.utils.PhoneNumberUtils;
import com.walker.infrastructure.utils.StringUtils;
 
import java.util.regex.Pattern;
 
/**
 * 配置表单验证工具。后续要合并到平台。
 * @author 时克英
 * @date 2023-05-20
 */
public class ConfigFormValidateUtils {
 
    /**
     * 手机
     * @param value String 值
     * @param info String 字段名
     */
    public static void isPhone(String value, String info) {
        regularException(value, info, RegularConstants.PHONE_TWO, "手机");
    }
 
    /**
     * 验证必填
     * @param value String 值
     * @param info String 字段名
 
     * @since 2020-05-11
     */
    public static void isRequire(String value, String info){
        if(StringUtils.isEmpty(value) ){
            throw new PlatformRuntimeException("请填写/选择" + info);
        }
    }
 
    /**
     * 正则表达式验证
     * @param value String 值
     * @param info String 字段名
     * @param regular String 正则表达式
 
     * @since 2020-05-11
     */
    public static void regularException(String value, String info, String regular, String title){
        if(!regular(value, info, regular)){
            //正则验证
            throw new PlatformRuntimeException(info + " 格式必须为 " + title);
        }
    }
 
    /**
     * 正则表达式验证
     * @param value String 值
     * @param info String 字段名
     * @param regular String 正则表达式
 
     * @since 2020-05-11
     */
    public static boolean regular(String value, String info, String regular){
        isRequire(value, info);
        Pattern pattern = Pattern.compile(regular);
        return pattern.matcher(value).matches();
    }
 
    /**
     * 校验是否是手机号,不是则抛出异常
     * @param phone 手机号
     */
    public static void isPhoneException(String phone) {
//        boolean match = false;
//        if(StringUtils.isEmpty(phone)){
//            match = false;
//        }
//        boolean match = ReUtil.isMatch(RegularConstants.PHONE_TWO, phone);
        boolean match = PhoneNumberUtils.isCellPhoneNumber(phone);
        if (!match) {
            throw new PlatformRuntimeException("请输入正确的手机号");
        }
    }
}