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
package com.cy.report.utils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegularUtil {
/**
* 去掉空格,匹配只含有 "英文字母数字中文._- "的字符串.
* @param s
* @return
*/
public static boolean regularECNPL(String s) {
s = s.replaceAll("\\s+","");
String regex = "^[A-Za-z0-9\u4E00-\u9FA5._-]+$";
boolean b = true;
if (s.length() > 100) {
b = false;
}
return s.matches(regex) && b;
}
/**
* 匹配密码 英文数字_,6到32位
* @param s
* @return
*/
public static boolean regularPass(String s) {
// String regex1 = "^[a-zA-Z0-9._-]{5,15}$";
// String regex2 = "[A-Z]";
// String regex3 = "[a-z]";
// String regex4 = "[1-9]";
// String regex5 = "[-_.]";
// Pattern pat1 = Pattern.compile(regex1);
// Matcher mat1 = pat1.matcher(s);
//
// Pattern pat2 = Pattern.compile(regex2);
// Matcher mat2 = pat2.matcher(s);
//
// Pattern pat3 = Pattern.compile(regex3);
// Matcher mat3 = pat3.matcher(s);
//
// Pattern pat4 = Pattern.compile(regex4);
// Matcher mat4 = pat4.matcher(s);
//
// Pattern pat5 = Pattern.compile(regex5);
// Matcher mat5 = pat5.matcher(s);
//
// if (mat1.find() && mat2.find() && mat3.find() && mat4.find() && mat5.find()) {
// return true;
// } else {
// return false;
// }
// return s.matches(".*?[^a-zA-Z\\d]+.*?")
// && s.matches(".*?[a-z]+.*?")
// && s.matches(".*?[A-Z]+.*?")
// && s.matches(".*?[\\d]+.*?")
// && s.matches("^.{6,16}$");
return s.matches("^[0-9a-zA-Z_]+$") && s.matches("^.{6,16}$");
}
/**
* 验证email格式.
* @param s
* @return
*/
public static boolean regularEmail(String s) {
String regex = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
return s.matches(regex);
}
/**
* 验证url格式.
* @param s
* @return
*/
public static boolean regularURL(String s) {
String regex = "(http|https|ftp)://([^/:]+)(:\\d*)?([^#\\s]*)";
return s.matches(regex);
}
public static void main(String[] args) {
String s = "aaaaaa";
System.out.println(s.matches("^(?![0-9]+$)(?![a-z]+$)(([0-9a-z])|([0-9a-zA-Z])|([0-9a-z!@#$%^&*()])|([0-9a-zA-Z!@#$%^&*()])){6,16}$"));
}
}