身份證正確校驗工具類

2021-10-08 20:21:09 字數 1459 閱讀 1813

具體就不去講為什麼,直接上**。

public class idcardutil " // 6位地區碼

+ "(18|19|([23]\\d))\\d" // 年yyyy

+ "((0[1-9])|(10|11|12))" // 月mm

+ "(([0-2][1-9])|10|20|30|31)" // 日dd

+ "\\d" // 3位順序碼

+ "[0-9xx]" // 校驗碼

+ "$";

private static mapresults = new hashmap<>();

static

public static void main(string args)

public static boolean compare(string idcardnum)

if (!regexmatch(idcardnum, regex_id_no_18))

return checkcode(idcardnum);

}/**

* 校驗字串長度

** @param inputstring 字串

* @param len 預期長度

* @return true - 校驗通過

* false - 校驗不通過

*/private static boolean checkstrlength(string inputstring, int len)

return true;

}/**

* 匹配正規表示式

** @param inputstring 字串

* @param regex 正規表示式

* @return true - 校驗通過

* false - 校驗不通過

*/private static boolean regexmatch(string inputstring, string regex)

/*** 計算校驗碼

*/private static boolean checkcode(string idno18) ;

int sum = 0;

char idnoarray = idno18.tochararray();

for (int i = 0; i < loading.length; i++)

int key = sum % 11;

string s = results.get(string.valueof(key));

string input = string.valueof(idnoarray[17]);

if (input.equals("x") && s.equals("x"))

return input.equals(s);

}

當初做這個的時候參考了,其他部落格,但是**不中,官方有身份證號碼生成的具體邏輯根據這個邏輯寫出來並不是很複雜。

身份證校驗

int isright string card cout 9 wi sum 11 if p 17 x p 17 x 最後一位為 x 或 x else if id wi p 17 判斷計算出的身份證校驗碼與輸入是否相符 return error 判斷身份證號碼中的年月日是否正確 bool birthd...

身份證校驗

const regexutils else 手機號碼格式驗證 checkmobile mobile string boolean return regex.test mobile.trim else 郵箱格式驗證 checkemail email string boolean result rege...

js校驗身份證

begin 校驗身份證 function checkidcard formname,inputname,itemname var area alert area parseint idcard.substr 0,2 var y,jym var s,m var idcard array new arr...