提交 c73e7a08 编写于 作者: B Blankj

see 08/29 log

上级 1bd2f343
......@@ -32,7 +32,7 @@
## Contact
[![Blog][blogsvg]][blog] [![jianshu][jianshusvg]][jianshu] [![weibo][weibosvg]][weibo] [![QQ0Group][qq0groupsvg]][qq0group] [![QQ1Group][qq1groupsvg]][qq1group]
[![Blog][blogsvg]][blog] [![jianshu][jianshusvg]][jianshu] [![weibo][weibosvg]][weibo] [![QQGroup][qqgroupsvg]][qqgroup]
## [Update Log][update_log.md]
......@@ -78,8 +78,5 @@
[weibosvg]: https://img.shields.io/badge/weibo-@__Blankj-34a48e.svg
[weibo]: http://weibo.com/3076228982
[qq0groupsvg]: https://img.shields.io/badge/QQ群0(满)-74721490-ff73a3.svg
[qq0group]: https://shang.qq.com/wpa/qunwpa?idkey=62baf2c3ec6b0863155b0c7a10c71bba2608cb0b6532fc18515835e54c69bdd3
[qq1groupsvg]: https://img.shields.io/badge/QQ群1-25206533-ff73a3.svg
[qq1group]: https://shang.qq.com/wpa/qunwpa?idkey=d906789f84484465e2736f7b524366b4c23afeda38733d5c7b10fc3f6e406e9b
[qqgroupsvg]: https://img.shields.io/badge/QQ群-25206533-34a48e.svg
[qqgroup]: https://shang.qq.com/wpa/qunwpa?idkey=d906789f84484465e2736f7b524366b4c23afeda38733d5c7b10fc3f6e406e9b
* 18/08/28 新增 RegexUtils#isIDCard18Exact
* 18/08/26 新增 AppUtils#getAppSignatureSHA256 和 AppUtils#getAppSignatureMD5,发布 1.19.3
* 18/08/24 新增 ScreenUtils#restoreAdaptScreen,利用 FileProvider4UtilCode 不再需要初始化,发布 1.19.2
* 18/08/23 修复适配后 ToastUtils 原生 Toast 尺寸发生改变的问题,修复 KeyboardUtils#fixSoftInputLeaks,发布 1.19.1
......
......@@ -481,11 +481,12 @@ get : 获取反射想要获取的
* ### 正则相关 -> [RegexUtils.java][regex.java] -> [Test][regex.test]
```
isMobileSimple : 验证手机号(简单)
isMobileExact : 验证手机号(精确)
isMobileSimple : 简单验证手机号
isMobileExact : 精确验证手机号
isTel : 验证电话号码
isIDCard15 : 验证身份证号码 15 位
isIDCard18 : 验证身份证号码 18 位
isIDCard18 : 简单验证身份证号码 18 位
isIDCard18Exact: 精确验证身份证号码 18 位
isEmail : 验证邮箱
isURL : 验证 URL
isZh : 验证汉字
......
......@@ -486,6 +486,7 @@ isMobileExact
isTel
isIDCard15
isIDCard18
isIDCard18Exact
isEmail
isURL
isZh
......
package com.blankj.utilcode.util;
import android.support.v4.util.SimpleArrayMap;
import com.blankj.utilcode.constant.RegexConstants;
import java.util.ArrayList;
......@@ -18,6 +20,8 @@ import java.util.regex.Pattern;
*/
public final class RegexUtils {
private final static SimpleArrayMap<String, String> CITY_MAP = new SimpleArrayMap<>();
private RegexUtils() {
throw new UnsupportedOperationException("u can't instantiate me...");
}
......@@ -76,6 +80,72 @@ public final class RegexUtils {
return isMatch(RegexConstants.REGEX_ID_CARD18, input);
}
/**
* Return whether input matches regex of exact id card number which length is 18.
*
* @param input The input.
* @return {@code true}: yes<br>{@code false}: no
*/
public static boolean isIDCard18Exact(final CharSequence input) {
if (isIDCard18(input)) {
int[] factor = new int[]{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
char[] suffix = new char[]{'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
if (CITY_MAP.isEmpty()) {
CITY_MAP.put("11", "北京");
CITY_MAP.put("12", "天津");
CITY_MAP.put("13", "河北");
CITY_MAP.put("14", "山西");
CITY_MAP.put("15", "内蒙古");
CITY_MAP.put("21", "辽宁");
CITY_MAP.put("22", "吉林");
CITY_MAP.put("23", "黑龙江");
CITY_MAP.put("31", "上海");
CITY_MAP.put("32", "江苏");
CITY_MAP.put("33", "浙江");
CITY_MAP.put("34", "安徽");
CITY_MAP.put("35", "福建");
CITY_MAP.put("36", "江西");
CITY_MAP.put("37", "山东");
CITY_MAP.put("41", "河南");
CITY_MAP.put("42", "湖北");
CITY_MAP.put("43", "湖南");
CITY_MAP.put("44", "广东");
CITY_MAP.put("45", "广西");
CITY_MAP.put("46", "海南");
CITY_MAP.put("50", "重庆");
CITY_MAP.put("51", "四川");
CITY_MAP.put("52", "贵州");
CITY_MAP.put("53", "云南");
CITY_MAP.put("54", "西藏");
CITY_MAP.put("61", "陕西");
CITY_MAP.put("62", "甘肃");
CITY_MAP.put("63", "青海");
CITY_MAP.put("64", "宁夏");
CITY_MAP.put("65", "新疆");
CITY_MAP.put("71", "台湾");
CITY_MAP.put("81", "香港");
CITY_MAP.put("82", "澳门");
CITY_MAP.put("91", "国外");
}
if (CITY_MAP.get(input.subSequence(0, 2).toString()) != null) {
int weightSum = 0;
for (int i = 0; i < 17; ++i) {
weightSum += (input.charAt(i) - '0') * factor[i];
}
int idCardMod = weightSum % 11;
char idCardLast = input.charAt(17);
return idCardLast == suffix[idCardMod];
}
}
return false;
}
/**
* Return whether input matches regex of email.
*
......
......@@ -55,6 +55,13 @@ public class RegexUtilsTest {
assertFalse(RegexUtils.isIDCard18("336984184021125233"));
}
@Test
public void isIDCard18Exact() {
assertFalse(RegexUtils.isIDCard18Exact("33698418400112523x"));
assertTrue(RegexUtils.isIDCard18Exact("336984184001125233"));
assertFalse(RegexUtils.isIDCard18Exact("336984184021125233"));
}
@Test
public void isEmail() {
assertTrue(RegexUtils.isEmail("blankj@qq.com"));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册