1
zj
2024-06-13 8eea5be3b36875bd4ffe70e6c3a5bb07b1d829bf
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
package com.yami.trading.common.util;
 
import cn.hutool.core.util.StrUtil;
 
import java.util.regex.Pattern;
 
/**
 * 正则表达式工具
 * @author LGH
 */
public class PrincipalUtil {
 
    /**
     * 以1开头,后面跟10位数
     */
    public static final String MOBILE_REGEXP = "1[0-9]{10}";
 
    /**
     * 数字字母下划线 4-16位
     */
    public static final String USER_NAME_REGEXP = "([a-zA-Z0-9_]{4,16})";
 
    /**
     * 由简单的字母数字拼接而成的字符串 不含有下划线,大写字母
     */
    public static final String SIMPLE_CHAR_REGEXP = "([a-z0-9]+)";
 
    public static boolean isMobile(String value) {
        if(StrUtil.isBlank(value)) {
            return false;
        }
        return Pattern.matches(MOBILE_REGEXP, value);
    }
 
    public static boolean isUserName(String value) {
        if(StrUtil.isBlank(value)) {
            return false;
        }
        return Pattern.matches(USER_NAME_REGEXP, value);
    }
 
    public static boolean isMatching(String regexp, String value) {
        if (StrUtil.isBlank(value)) {
            return false;
        }
        return Pattern.matches(regexp, value);
    }
 
    /**
     * 是否是由简单的字母数字拼接而成的字符串
     * @param value 输入值
     * @return 匹配结果
     */
    public static boolean isSimpleChar(String value) {
        return isMatching(SIMPLE_CHAR_REGEXP, value);
    }
}