forked from chenssy89/jutils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegexUtils.java
More file actions
89 lines (82 loc) · 1.96 KB
/
RegexUtils.java
File metadata and controls
89 lines (82 loc) · 1.96 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
package com.JUtils.base;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 正则表达式工具类,验证数据是否符合规范
*
* @Author:chenssy
* @date:2014年8月7日
*/
public class RegexUtils {
/**
* 判断字符串是否符合正则表达式
*
* @author : chenssy
* @date : 2016年6月1日 下午12:43:05
*
* @param str
* @param regex
* @return
*/
public static boolean find(String str, String regex) {
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(str);
boolean b = m.find();
return b;
}
/**
* 判断输入的字符串是否符合Email格式.
* @autor:chenssy
* @date:2014年8月7日
*
* @param email
* 传入的字符串
* @return 符合Email格式返回true,否则返回false
*/
public static boolean isEmail(String email) {
if (email == null || email.length() < 1 || email.length() > 256) {
return false;
}
Pattern pattern = Pattern.compile("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$");
return pattern.matcher(email).matches();
}
/**
* 判断输入的字符串是否为纯汉字
* @autor:chenssy
* @date:2014年8月7日
*
* @param value
* 传入的字符串
* @return
*/
public static boolean isChinese(String value) {
Pattern pattern = Pattern.compile("[\u0391-\uFFE5]+$");
return pattern.matcher(value).matches();
}
/**
* 判断是否为浮点数,包括double和float
* @autor:chenssy
* @date:2014年8月7日
*
* @param value
* 传入的字符串
* @return
*/
public static boolean isDouble(String value) {
Pattern pattern = Pattern.compile("^[-\\+]?\\d+\\.\\d+$");
return pattern.matcher(value).matches();
}
/**
* 判断是否为整数
* @autor:chenssy
* @date:2014年8月7日
*
* @param value
* 传入的字符串
* @return
*/
public static boolean isInteger(String value) {
Pattern pattern = Pattern.compile("^[-\\+]?[\\d]+$");
return pattern.matcher(value).matches();
}
}