RegularUtils.java
3.5 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package com.sunvote.util;
import java.util.regex.Pattern;
/**
* Created by Elvis on 2017/8/15 15:03
* Email:Eluis@psunsky.com
* 版权所有:长沙中天电子设计开发有限公司
* Description: 工具包
*/
public class RegularUtils {
private RegularUtils() {
throw new UnsupportedOperationException("No Impl");
}
/**
* 验证手机号(简单)
*
* @param string 待验证文本
* @return true: 匹配<br>false: 不匹配
*/
public static boolean isMobileSimple(String string) {
return isMatch(ConstUtils.REGEX_MOBILE_SIMPLE, string);
}
/**
* 验证手机号(精确)
*
* @param string 待验证文本
* @return true: 匹配<br>false: 不匹配
*/
public static boolean isMobileExact(String string) {
return isMatch(ConstUtils.REGEX_MOBILE_EXACT, string);
}
/**
* 验证电话号码
*
* @param string 待验证文本
* @return true: 匹配<br>false: 不匹配
*/
public static boolean isTel(String string) {
return isMatch(ConstUtils.REGEX_TEL, string);
}
/**
* 验证身份证号码15位
*
* @param string 待验证文本
* @return true: 匹配<br>false: 不匹配
*/
public static boolean isIDCard15(String string) {
return isMatch(ConstUtils.REGEX_IDCARD15, string);
}
/**
* 验证身份证号码18位
*
* @param string 待验证文本
* @return true: 匹配<br>false: 不匹配
*/
public static boolean isIDCard18(String string) {
return isMatch(ConstUtils.REGEX_IDCARD18, string);
}
/**
* 验证邮箱
*
* @param string 待验证文本
* @return true: 匹配<br>false: 不匹配
*/
public static boolean isEmail(String string) {
return isMatch(ConstUtils.REGEX_EMAIL, string);
}
/**
* 验证URL
*
* @param string 待验证文本
* @return true: 匹配<br>false: 不匹配
*/
public static boolean isURL(String string) {
return isMatch(ConstUtils.REGEX_URL, string);
}
/**
* 验证汉字
*
* @param string 待验证文本
* @return true: 匹配<br>false: 不匹配
*/
public static boolean isChz(String string) {
return isMatch(ConstUtils.REGEX_CHZ, string);
}
/**
* 验证用户名
* <p>取值范围为a-z,A-Z,0-9,"_",汉字,不能以"_"结尾,用户名必须是6-20位</p>
*
* @param string 待验证文本
* @return true: 匹配<br>false: 不匹配
*/
public static boolean isUsername(String string) {
return isMatch(ConstUtils.REGEX_USERNAME, string);
}
/**
* 验证yyyy-MM-dd格式的日期校验,已考虑平闰年
*
* @param string 待验证文本
* @return true: 匹配<br>false: 不匹配
*/
public static boolean isDate(String string) {
return isMatch(ConstUtils.REGEX_DATE, string);
}
/**
* 验证IP地址
*
* @param string 待验证文本
* @return true: 匹配<br>false: 不匹配
*/
public static boolean isIP(String string) {
return isMatch(ConstUtils.REGEX_IP, string);
}
/**
* string是否匹配regex
*
* @param regex 正则表达式字符串
* @param string 要匹配的字符串
* @return true: 匹配<br>false: 不匹配
*/
public static boolean isMatch(String regex, String string) {
return !StringUtils.isEmpty(string) && Pattern.matches(regex, string);
}
}