yangys
2024-09-04 04c57331cf84c8f606c2838dcb6fe5463fb9b68c
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package com.qianwen.smartman.common.utils;
 
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
public class ValidatorUtils {
    public static final String REGEX_USERNAME = "^[a-zA-Z0-9]{6,20}$";
    public static final String REGEX_PASSWORD = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,15}$";
    public static final String REGEX_MOBILE = "^((13[0-9])|(14[0-9])|(15[^4,\\D])|(16[0-9])|(18[0-9])|(17[0-9])|(19[0-9]))\\d{8}$";
    public static final String REGEX_EMAIL = "^[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$";
    public static final String REGEX_CHINESE = "^[一-龥],{0,}$";
    public static final String REGEX_ID_CARD = "(^\\d{18}$)|(^\\d{15}$)";
    public static final String REGEX_URL = "http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?";
    public static final String REGEX_IP_ADDR = "(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)";
    public static final String REGEX_NUMBER = "^[-\\+]?[\\d]*$";
 
    public static boolean isUsername(String username) {
        return Pattern.matches(REGEX_USERNAME, username);
    }
 
    public static boolean isPassword(String password) {
        return Pattern.matches(REGEX_PASSWORD, password);
    }
 
    public static boolean isMobile(String mobile) {
        return Pattern.matches(REGEX_MOBILE, mobile);
    }
 
    public static boolean isEmail(String email) {
        return Pattern.matches(REGEX_EMAIL, email);
    }
 
    public static boolean isChinese(String chinese) {
        return Pattern.matches(REGEX_CHINESE, chinese);
    }
 
    public static boolean isIDCard(String idCard) {
        if (idCard.toUpperCase().matches("(^\\d{15}$)|(^\\d{17}([0-9]|X)$)")) {
            return true;
        }
        return false;
    }
 
    public static boolean isUrl(String url) {
        return Pattern.matches(REGEX_URL, url);
    }
 
    public static boolean isIPAddr(String ipAddr) {
        return Pattern.matches(REGEX_IP_ADDR, ipAddr);
    }
 
    public static boolean isCarCode(String carCode) {
        if (carCode.toUpperCase().matches("[一-龥]{1}[A-Z]{1}[A-Z_0-9]{5}")) {
            return true;
        }
        return false;
    }
 
    public static boolean isCarNo(String CarNum) {
        if (CarNum != null && !"".equals(CarNum)) {
            String s1 = CarNum.substring(0, 1);
            if ("京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼甲乙丙己庚辛壬寅辰戍午未申".contains(s1)) {
                String s2 = CarNum.substring(1, CarNum.length());
                if (!s2.contains("I") && !s2.contains("i") && !s2.contains("O") && !s2.contains("o") && !CarNum.matches("^[一-龥]{1}[A-Z]{1}[A-Z_0-9]{5}$")) {
                    return true;
                }
                return false;
            }
            return false;
        }
        return false;
    }
 
    public static boolean isLegalName(String name) {
        if (name.contains("·") || name.contains("•")) {
            if (name.matches("^[\\u4e00-\\u9fa5]+[·•][\\u4e00-\\u9fa5]+$")) {
                return true;
            }
            return false;
        } else if (name.matches("^[\\u4e00-\\u9fa5]+$")) {
            return true;
        } else {
            return false;
        }
    }
 
    public static boolean stringFilter(String str) {
        Pattern p = Pattern.compile("[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、? ]");
        Matcher m = p.matcher(str);
        return m.find();
    }
 
    public static boolean isNumber(String number) {
        return Pattern.matches(REGEX_NUMBER, number);
    }
 
    public static boolean checkContextLength(String context) {
        int length = context.length();
        return length > 32;
    }
 
    public static boolean checkContextLength(String context, int contextLength) {
        int length = context.length();
        return length > contextLength;
    }
 
    public static void main(String[] args) {
        System.out.println(isUsername("fdsdfsdj"));
        System.out.println(isChinese("fdsdfsdj"));
        System.out.println(isEmail("123@qq.com"));
        System.out.println(isMobile("13914265646"));
    }
}