-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckUtil.java
More file actions
61 lines (50 loc) · 1.32 KB
/
CheckUtil.java
File metadata and controls
61 lines (50 loc) · 1.32 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
package com.chen.util;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 检查工具类
* Created by chenwj3 on 2017/1/18.
*/
public class CheckUtil {
/**
* 判断字符串是不是null或无字符(trim)
*
* @param o
* @return
*/
public static Boolean isEmpty(String o) {
return (o == null || o.trim().length() == 0);
}
/**
* 判断字符串是不是数字
*
* @param str
* @return
*/
public static Boolean checkNum(String str) {
return !isEmpty(str) && str.matches("^\\d+$");
}
/**
* 判断字符串是否为数字,包括整数和小数.
*
* @param str
* @return
*/
public static boolean isNumeric(String str) {
Pattern pattern = Pattern.compile("^[-]?[0.0-9.0]+$");
Matcher isNum = pattern.matcher(str);
if (!isNum.matches()) {
return false;
}
return true;
}
public static void main(String[] args) {
System.out.println(isNumeric("1"));
System.out.println(isNumeric("-1"));
System.out.println(isNumeric("0"));
System.out.println(isNumeric("-3.2"));
System.out.println(isNumeric("3.2"));
System.out.println(isNumeric("1.3456"));
System.out.println(isNumeric("wqw12"));
}
}