RE validation in Java EE(java.util.regex.Pattern)
Posted ren9ie
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RE validation in Java EE(java.util.regex.Pattern)相关的知识,希望对你有一定的参考价值。
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
|
import java.util.regex.Pattern;<br> /** * 校验器:利用正则表达式校验邮箱、手机号等 * */ <br><br> public class Validator <br> /** * 正则表达式:验证用户名 */ //public static final String REGEX_USERNAME = "^[a-zA-Z]\\w5,17$"; public static final String REGEX_USERNAME = "^[a-zA-Z]\\w2,20$" ; <br> /** * 正则表达式:验证密码 */ public static final String REGEX_PASSWORD = "^[a-zA-Z0-9]6,16$" ; <br> /** * 正则表达式:验证手机号 */ // public static final String REGEX_MOBILE = "^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d8$"; public static final String REGEX_MOBILE = "^((13[0-9])|(15[^4,\\D])|(17[0-9])|(18[0-9]))\\d8$" ; <br> /** * 正则表达式:验证邮箱 */ public static final String REGEX_EMAIL = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]2,$" ; <br> /** * 校验用户名 * * @param username * @return 校验通过返回true,否则返回false */ public static boolean isUsername(String username) return Pattern.matches(REGEX_USERNAME, username); <br> /** * 校验密码 * * @param password * @return 校验通过返回true,否则返回false */ public static boolean isPassword(String password) return Pattern.matches(REGEX_PASSWORD, password); <br> /** * 校验手机号 * * @param mobile * @return 校验通过返回true,否则返回false */ public static boolean isMobile(String mobile) return Pattern.matches(REGEX_MOBILE, mobile); <br> /** * 校验邮箱 * * @param email * @return 校验通过返回true,否则返回false */ public static boolean isEmail(String email) return Pattern.matches(REGEX_EMAIL, email); public static void main(String[] args) String username = "fdsdfsdj" ; System.out.println(Validator.isUsername(username));
|
以上是关于RE validation in Java EE(java.util.regex.Pattern)的主要内容,如果未能解决你的问题,请参考以下文章
启动weblogic报错:string value '2.4' is not a valid enumeration value for web-app-versionType in
CHKJ3000E: WAR Validation Failed: org.eclipse.jst.j2ee.commonarchivecore.internal.exception.Deployme
java.lang.IllegalArgumentException: Invalid character found in the request target. The valid charact