|
|
|
@ -2,6 +2,7 @@ package com.dsideal.Base.Util;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
|
|
|
|
import java.text.ParseException;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
@ -30,7 +31,7 @@ public class IDCardUtil {
|
|
|
|
|
String tipInfo = "身份证正常";// 记录错误信息
|
|
|
|
|
String Ai = "";
|
|
|
|
|
|
|
|
|
|
if (null == IDStr || IDStr.trim().isEmpty()) {
|
|
|
|
|
if (IDStr.trim().isEmpty()) {
|
|
|
|
|
tipInfo = "身份证号码长度应该为15位或18位。";
|
|
|
|
|
jo.put("success", false);
|
|
|
|
|
jo.put("message", tipInfo);
|
|
|
|
@ -59,7 +60,7 @@ public class IDCardUtil {
|
|
|
|
|
String strYear = Ai.substring(6, 10);// 年份
|
|
|
|
|
String strMonth = Ai.substring(10, 12);// 月份
|
|
|
|
|
String strDay = Ai.substring(12, 14);// 日期
|
|
|
|
|
if (isDate(strYear + "-" + strMonth + "-" + strDay) == false) {
|
|
|
|
|
if (!isDate(strYear + "-" + strMonth + "-" + strDay)) {
|
|
|
|
|
tipInfo = "身份证出生日期无效。";
|
|
|
|
|
jo.put("success", false);
|
|
|
|
|
jo.put("message", tipInfo);
|
|
|
|
@ -75,9 +76,7 @@ public class IDCardUtil {
|
|
|
|
|
jo.put("message", tipInfo);
|
|
|
|
|
return jo;
|
|
|
|
|
}
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (java.text.ParseException e) {
|
|
|
|
|
} catch (NumberFormatException | ParseException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
if (Integer.parseInt(strMonth) > 12 || Integer.parseInt(strMonth) == 0) {
|
|
|
|
@ -93,7 +92,7 @@ public class IDCardUtil {
|
|
|
|
|
return jo;
|
|
|
|
|
}
|
|
|
|
|
// 判断地区码是否有效
|
|
|
|
|
Hashtable areacode = GetAreaCode();
|
|
|
|
|
Map<String,String> areacode = getAreaCode();
|
|
|
|
|
// 如果身份证前两位的地区码不在Hashtable,则地区码有误
|
|
|
|
|
if (areacode.get(Ai.substring(0, 2)) == null) {
|
|
|
|
|
tipInfo = "身份证地区编码错误。";
|
|
|
|
@ -102,7 +101,7 @@ public class IDCardUtil {
|
|
|
|
|
return jo;
|
|
|
|
|
}
|
|
|
|
|
//判断第18位校验码是否正确
|
|
|
|
|
if (isVarifyCode(Ai, IDStr) == false) {
|
|
|
|
|
if (!isVarifyCode(Ai, IDStr)) {
|
|
|
|
|
tipInfo = "身份证校验码无效,不是合法的身份证号码";
|
|
|
|
|
jo.put("success", false);
|
|
|
|
|
jo.put("message", tipInfo);
|
|
|
|
@ -188,44 +187,44 @@ public class IDCardUtil {
|
|
|
|
|
*
|
|
|
|
|
* @return Hashtable 对象
|
|
|
|
|
*/
|
|
|
|
|
private static Hashtable GetAreaCode() {
|
|
|
|
|
Hashtable hashtable = new Hashtable();
|
|
|
|
|
hashtable.put("11", "北京");
|
|
|
|
|
hashtable.put("12", "天津");
|
|
|
|
|
hashtable.put("13", "河北");
|
|
|
|
|
hashtable.put("14", "山西");
|
|
|
|
|
hashtable.put("15", "内蒙古");
|
|
|
|
|
hashtable.put("21", "辽宁");
|
|
|
|
|
hashtable.put("22", "吉林");
|
|
|
|
|
hashtable.put("23", "黑龙江");
|
|
|
|
|
hashtable.put("31", "上海");
|
|
|
|
|
hashtable.put("32", "江苏");
|
|
|
|
|
hashtable.put("33", "浙江");
|
|
|
|
|
hashtable.put("34", "安徽");
|
|
|
|
|
hashtable.put("35", "福建");
|
|
|
|
|
hashtable.put("36", "江西");
|
|
|
|
|
hashtable.put("37", "山东");
|
|
|
|
|
hashtable.put("41", "河南");
|
|
|
|
|
hashtable.put("42", "湖北");
|
|
|
|
|
hashtable.put("43", "湖南");
|
|
|
|
|
hashtable.put("44", "广东");
|
|
|
|
|
hashtable.put("45", "广西");
|
|
|
|
|
hashtable.put("46", "海南");
|
|
|
|
|
hashtable.put("50", "重庆");
|
|
|
|
|
hashtable.put("51", "四川");
|
|
|
|
|
hashtable.put("52", "贵州");
|
|
|
|
|
hashtable.put("53", "云南");
|
|
|
|
|
hashtable.put("54", "西藏");
|
|
|
|
|
hashtable.put("61", "陕西");
|
|
|
|
|
hashtable.put("62", "甘肃");
|
|
|
|
|
hashtable.put("63", "青海");
|
|
|
|
|
hashtable.put("64", "宁夏");
|
|
|
|
|
hashtable.put("65", "新疆");
|
|
|
|
|
hashtable.put("71", "台湾");
|
|
|
|
|
hashtable.put("81", "香港");
|
|
|
|
|
hashtable.put("82", "澳门");
|
|
|
|
|
hashtable.put("91", "国外");
|
|
|
|
|
return hashtable;
|
|
|
|
|
private static Map<String, String> getAreaCode() {
|
|
|
|
|
Map<String, String> areaCodeMap = new HashMap<>();
|
|
|
|
|
areaCodeMap.put("11", "北京");
|
|
|
|
|
areaCodeMap.put("12", "天津");
|
|
|
|
|
areaCodeMap.put("13", "河北");
|
|
|
|
|
areaCodeMap.put("14", "山西");
|
|
|
|
|
areaCodeMap.put("15", "内蒙古");
|
|
|
|
|
areaCodeMap.put("21", "辽宁");
|
|
|
|
|
areaCodeMap.put("22", "吉林");
|
|
|
|
|
areaCodeMap.put("23", "黑龙江");
|
|
|
|
|
areaCodeMap.put("31", "上海");
|
|
|
|
|
areaCodeMap.put("32", "江苏");
|
|
|
|
|
areaCodeMap.put("33", "浙江");
|
|
|
|
|
areaCodeMap.put("34", "安徽");
|
|
|
|
|
areaCodeMap.put("35", "福建");
|
|
|
|
|
areaCodeMap.put("36", "江西");
|
|
|
|
|
areaCodeMap.put("37", "山东");
|
|
|
|
|
areaCodeMap.put("41", "河南");
|
|
|
|
|
areaCodeMap.put("42", "湖北");
|
|
|
|
|
areaCodeMap.put("43", "湖南");
|
|
|
|
|
areaCodeMap.put("44", "广东");
|
|
|
|
|
areaCodeMap.put("45", "广西");
|
|
|
|
|
areaCodeMap.put("46", "海南");
|
|
|
|
|
areaCodeMap.put("50", "重庆");
|
|
|
|
|
areaCodeMap.put("51", "四川");
|
|
|
|
|
areaCodeMap.put("52", "贵州");
|
|
|
|
|
areaCodeMap.put("53", "云南");
|
|
|
|
|
areaCodeMap.put("54", "西藏");
|
|
|
|
|
areaCodeMap.put("61", "陕西");
|
|
|
|
|
areaCodeMap.put("62", "甘肃");
|
|
|
|
|
areaCodeMap.put("63", "青海");
|
|
|
|
|
areaCodeMap.put("64", "宁夏");
|
|
|
|
|
areaCodeMap.put("65", "新疆");
|
|
|
|
|
areaCodeMap.put("71", "台湾");
|
|
|
|
|
areaCodeMap.put("81", "香港");
|
|
|
|
|
areaCodeMap.put("82", "澳门");
|
|
|
|
|
areaCodeMap.put("91", "国外");
|
|
|
|
|
return areaCodeMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|