Skip to content

Commit c8b4380

Browse files
committed
see 08/16 log
1 parent ec47f3e commit c8b4380

17 files changed

+740
-140
lines changed

README.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
> - 打开指定包名的App *openAppByPackageName*
1111
> - 打开指定包名的App应用信息界面 *openAppInfo*
1212
> - 可用来做App信息分享 *shareAppInfo*
13-
> - 判断当前App处于前台还是后台 *isApplicationBackground*
13+
> - 判断当前App处于前台还是后台 *isAppBackground*
1414
1515
> - [常量相关][const.md][ConstUtils.java][const.java]
1616
> - 存储相关常量
@@ -99,7 +99,18 @@
9999
> - 获取手机短信并保存到xml中 *getAllSMS*
100100
101101
> - [正则相关][regular.md][RegularUtils.java][regular.java]
102-
> - 正则工具类
102+
> - 验证手机号(简单) *isMobileSimple*
103+
> - 验证手机号(精确) *isMobileExact*
104+
> - 验证电话号码 *isTel*
105+
> - 验证身份证号码15位 *isIDCard15*
106+
> - 验证身份证号码18位 *isIDCard18*
107+
> - 验证邮箱 *isEmail*
108+
> - 验证URL *isURL*
109+
> - 验证汉字 *isChz*
110+
> - 验证用户名 *isUsername*
111+
> - 验证yyyy-MM-dd格式的日期校验,已考虑平闰年 *isDate*
112+
> - 验证IP地址 *isIP*
113+
> - string是否匹配regex *isMatch*
103114
104115
> - [屏幕相关][screen.md][ScreenUtils.java][screen.java]
105116
> - 获取手机分辨率 *getDeviceWidth**getDeviceHeight*
@@ -142,6 +153,16 @@
142153
> - SP中写入boolean类型value *putBoolean*
143154
> - SP中读取boolean *getBoolean*
144155
156+
> - [字符串相关][string.md][StringUtils.java][string.java]
157+
> - 判断字符串是否为null或长度为0 *isEmpty*
158+
> - 判断字符串是否为null或全为空格 *isSpace*
159+
> - null转为长度为0的字符串 *null2Length0*
160+
> - 返回字符串长度 *length*
161+
> - 首字母大写 *upperFirstLetter*
162+
> - 首字母小写 *lowerFirstLetter*
163+
> - 转化为半角字符 *toDBC*
164+
> - 转化为全角字符 *toSBC*
165+
145166
> - [时间相关][time.md][TimeUtils.java][time.java]
146167
> - 将时间戳转为时间字符串 *milliseconds2String*
147168
> - 将时间字符串转为时间戳 *string2Milliseconds*
@@ -230,6 +251,8 @@ limitations under the License.
230251
[size.java]: https://github.com/Blankj/AndroidUtilCode/blob/master/utilcode/src/main/java/com/blankj/utilcode/utils/SizeUtils.java
231252
[sp.md]: https://github.com/Blankj/AndroidUtilCode/blob/master/md/about_sp.md
232253
[sp.java]: https://github.com/Blankj/AndroidUtilCode/blob/master/utilcode/src/main/java/com/blankj/utilcode/utils/SPUtils.java
254+
[string.md]: https://github.com/Blankj/AndroidUtilCode/blob/master/md/about_string.md
255+
[string.java]: https://github.com/Blankj/AndroidUtilCode/blob/master/utilcode/src/main/java/com/blankj/utilcode/utils/StringUtils.java
233256
[time.md]: https://github.com/Blankj/AndroidUtilCode/blob/master/md/about_time.md
234257
[time.java]: https://github.com/Blankj/AndroidUtilCode/blob/master/utilcode/src/main/java/com/blankj/utilcode/utils/TimeUtils.java
235258
[unclassified.md]: https://github.com/Blankj/AndroidUtilCode/blob/master/md/unclassified.md

md/about_const.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# 常量相关
22
``` java
3+
package com.blankj.utilcode.utils;
4+
35
/**
46
* <pre>
57
* author: Blankj
@@ -53,5 +55,56 @@ public class ConstUtils {
5355
* 天与毫秒的倍数
5456
*/
5557
public static final int DAY = 86400000;
58+
59+
/******************** 正则相关常量 ********************/
60+
/**
61+
* 正则:手机号(简单)
62+
*/
63+
public static final String REGEX_MOBILE_SIMPLE = "^[1]\\d{10}$";
64+
/**
65+
* 正则:手机号(精确)
66+
* <p>移动:134(0-8)、135、136、137、138、139、147、150、151、152、157、158、159、178、182、183、184、187、188</p>
67+
* <p>联通:130、131、132、145、155、156、175、176、185、186</p>
68+
* <p>电信:133、153、173、177、180、181、189</p>
69+
* <p>全球星:1349</p>
70+
* <p>虚拟运营商:170</p>
71+
*/
72+
public static final String REGEX_MOBILE_EXACT = "^((13[0-9])|(14[5,7])|(15[0-3,5-8])|(17[0,3,5-8])|(18[0-9])|(147))\\d{8}$";
73+
/**
74+
* 正则:电话号码
75+
*/
76+
public static final String REGEX_TEL = "^0\\d{2,3}[- ]?\\d{7,8}";
77+
/**
78+
* 正则:身份证号码15位
79+
*/
80+
public static final String REGEX_IDCARD15 = "^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$";
81+
/**
82+
* 正则:身份证号码18位
83+
*/
84+
public static final String REGEX_IDCARD18 = "^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9Xx])$";
85+
/**
86+
* 正则:邮箱
87+
*/
88+
public static final String REGEX_EMAIL = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
89+
/**
90+
* 正则:URL
91+
*/
92+
public static final String REGEX_URL = "http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?";
93+
/**
94+
* 正则:汉字
95+
*/
96+
public static final String REGEX_CHZ = "^[\\u4e00-\\u9fa5]+$";
97+
/**
98+
* 正则:用户名,取值范围为a-z,A-Z,0-9,"_",汉字,不能以"_"结尾,用户名必须是6-20位
99+
*/
100+
public static final String REGEX_USERNAME = "^[\\w\\u4e00-\\u9fa5]{6,20}(?<!_)$";
101+
/**
102+
* 正则:yyyy-MM-dd格式的日期校验,已考虑平闰年
103+
*/
104+
public static final String REGEX_DATE = "^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$";
105+
/**
106+
* 正则:IP地址
107+
*/
108+
public static final String REGEX_IP = "((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)";
56109
}
57110
```

md/about_file.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 编码解码相关
1+
# 文件相关
22
``` java
33
/**
44
* <pre>

md/about_image.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 编码解码相关
1+
# 图片相关
22
``` java
33
/**
44
* <pre>

md/about_phone.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import android.net.Uri;
88
import android.os.SystemClock;
99
import android.provider.Settings;
1010
import android.telephony.TelephonyManager;
11-
import android.text.TextUtils;
1211
import android.util.Log;
1312
import android.util.Xml;
1413

@@ -136,9 +135,9 @@ public class PhoneUtils {
136135
* @param content 内容
137136
*/
138137
public static void sendSms(Context context, String phoneNumber, String content) {
139-
Uri uri = Uri.parse("smsto:" + (TextUtils.isEmpty(phoneNumber) ? "" : phoneNumber));
138+
Uri uri = Uri.parse("smsto:" + (StringUtils.isEmpty(phoneNumber) ? "" : phoneNumber));
140139
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
141-
intent.putExtra("sms_body", TextUtils.isEmpty(content) ? "" : content);
140+
intent.putExtra("sms_body", StringUtils.isEmpty(content) ? "" : content);
142141
context.startActivity(intent);
143142
}
144143

@@ -172,7 +171,7 @@ public class PhoneUtils {
172171
// cursor.getString(cursor.getColumnIndex("contact_id"));//getColumnIndex
173172
// : 查询字段在cursor中索引值,一般都是用在查询字段比较多的时候
174173
// 判断contact_id是否为空
175-
if (!TextUtils.isEmpty(contact_id)) {//null ""
174+
if (!StringUtils.isEmpty(contact_id)) {//null ""
176175
// 7.根据contact_id查询view_data表中的数据
177176
// selection : 查询条件
178177
// selectionArgs :查询条件的参数

md/about_regular.md

Lines changed: 70 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# 正则相关
22
``` java
3-
import android.text.TextUtils;
3+
package com.blankj.utilcode.utils;
44

55
import java.util.regex.Pattern;
66

7+
import static com.blankj.utilcode.utils.ConstUtils.*;
8+
79
/**
810
* <pre>
911
* author: Blankj
@@ -19,109 +21,129 @@ public class RegularUtils {
1921
}
2022

2123
/**
22-
* 验证手机号(简单)
23-
*/
24-
private static final String REGEX_MOBILE_SIMPLE = "^[1]\\d{10}$";
25-
/**
26-
* 验证手机号(精确)
27-
* <p/>
28-
* <p>移动:134(0-8)、135、136、137、138、139、147、150、151、152、157、158、159、178、182、183、184、187、188
29-
* <p>联通:130、131、132、145、155、156、175、176、185、186
30-
* <p>电信:133、153、173、177、180、181、189
31-
* <p>全球星:1349
32-
* <p>虚拟运营商:170
33-
*/
34-
private static final String REGEX_MOBILE_EXACT = "^((13[0-9])|(14[5,7])|(15[0-3,5-8])|(17[0,3,5-8])|(18[0-9])|(147))\\d{8}$";
35-
/**
36-
* 验证座机号,正确格式:xxx/xxxx-xxxxxxx/xxxxxxxx/
37-
*/
38-
private static final String REGEX_TEL = "^0\\d{2,3}[- ]?\\d{7,8}";
39-
/**
40-
* 验证邮箱
41-
*/
42-
private static final String REGEX_EMAIL = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
43-
/**
44-
* 验证url
24+
* If u want more please visit http://toutiao.com/i6231678548520731137/
4525
*/
46-
private static final String REGEX_URL = "http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?";
47-
/**
48-
* 验证汉字
49-
*/
50-
private static final String REGEX_CHZ = "^[\\u4e00-\\u9fa5]+$";
51-
/**
52-
* 验证用户名,取值范围为a-z,A-Z,0-9,"_",汉字,不能以"_"结尾,用户名必须是6-20位
53-
*/
54-
private static final String REGEX_USERNAME = "^[\\w\\u4e00-\\u9fa5]{6,20}(?<!_)$";
55-
/**
56-
* 验证IP地址
57-
*/
58-
private static final String REGEX_IP = "((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)";
59-
60-
//If u want more please visit http://toutiao.com/i6231678548520731137/
6126

6227
/**
28+
* 验证手机号(简单)
29+
*
6330
* @param string 待验证文本
64-
* @return 是否符合手机号(简单)格式
31+
* @return true: 匹配<br>false: 不匹配
6532
*/
6633
public static boolean isMobileSimple(String string) {
6734
return isMatch(REGEX_MOBILE_SIMPLE, string);
6835
}
6936

7037
/**
38+
* 验证手机号(精确)
39+
*
7140
* @param string 待验证文本
72-
* @return 是否符合手机号(精确)格式
41+
* @return true: 匹配<br>false: 不匹配
7342
*/
7443
public static boolean isMobileExact(String string) {
7544
return isMatch(REGEX_MOBILE_EXACT, string);
7645
}
7746

7847
/**
48+
* 验证电话号码
49+
*
7950
* @param string 待验证文本
80-
* @return 是否符合座机号码格式
51+
* @return true: 匹配<br>false: 不匹配
8152
*/
8253
public static boolean isTel(String string) {
8354
return isMatch(REGEX_TEL, string);
8455
}
8556

8657
/**
58+
* 验证身份证号码15位
59+
*
8760
* @param string 待验证文本
88-
* @return 是否符合邮箱格式
61+
* @return true: 匹配<br>false: 不匹配
62+
*/
63+
public static boolean isIDCard15(String string) {
64+
return isMatch(REGEX_IDCARD15, string);
65+
}
66+
67+
/**
68+
* 验证身份证号码18位
69+
*
70+
* @param string 待验证文本
71+
* @return true: 匹配<br>false: 不匹配
72+
*/
73+
public static boolean isIDCard18(String string) {
74+
return isMatch(REGEX_IDCARD18, string);
75+
}
76+
77+
/**
78+
* 验证邮箱
79+
*
80+
* @param string 待验证文本
81+
* @return true: 匹配<br>false: 不匹配
8982
*/
9083
public static boolean isEmail(String string) {
9184
return isMatch(REGEX_EMAIL, string);
9285
}
9386

9487
/**
88+
* 验证URL
89+
*
9590
* @param string 待验证文本
96-
* @return 是否符合网址格式
91+
* @return true: 匹配<br>false: 不匹配
9792
*/
9893
public static boolean isURL(String string) {
9994
return isMatch(REGEX_URL, string);
10095
}
10196

10297
/**
98+
* 验证汉字
99+
*
103100
* @param string 待验证文本
104-
* @return 是否符合汉字
101+
* @return true: 匹配<br>false: 不匹配
105102
*/
106103
public static boolean isChz(String string) {
107104
return isMatch(REGEX_CHZ, string);
108105
}
109106

110107
/**
108+
* 验证用户名
109+
* <p>取值范围为a-z,A-Z,0-9,"_",汉字,不能以"_"结尾,用户名必须是6-20位</p>
110+
*
111111
* @param string 待验证文本
112-
* @return 是否符合用户名
112+
* @return true: 匹配<br>false: 不匹配
113113
*/
114114
public static boolean isUsername(String string) {
115115
return isMatch(REGEX_USERNAME, string);
116116
}
117117

118118
/**
119+
* 验证yyyy-MM-dd格式的日期校验,已考虑平闰年
120+
*
121+
* @param string 待验证文本
122+
* @return true: 匹配<br>false: 不匹配
123+
*/
124+
public static boolean isDate(String string) {
125+
return isMatch(REGEX_DATE, string);
126+
}
127+
128+
/**
129+
* 验证IP地址
130+
*
131+
* @param string 待验证文本
132+
* @return true: 匹配<br>false: 不匹配
133+
*/
134+
public static boolean isIP(String string) {
135+
return isMatch(REGEX_IP, string);
136+
}
137+
138+
/**
139+
* string是否匹配regex
140+
*
119141
* @param regex 正则表达式字符串
120142
* @param string 要匹配的字符串
121-
* @return 如果str 符合 regex的正则表达式格式,返回true, 否则返回 false;
143+
* @return true: 匹配<br>false: 不匹配
122144
*/
123145
public static boolean isMatch(String regex, String string) {
124-
return !TextUtils.isEmpty(string) && Pattern.matches(regex, string);
146+
return !StringUtils.isEmpty(string) && Pattern.matches(regex, string);
125147
}
126148
}
127149
```

0 commit comments

Comments
 (0)