【代码片段】正则
2022/03/08 22:50:04
校验身份证号码
function checkIdentity(e) {
if (/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/.test(e) && 18 == e.length) {
for (var t = new Array(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2), n = new Array(1,0,10,9,8,7,6,5,4,3,2), r = 0, i = 0; i < 17; i++)
r += e.substring(i, i + 1) * t[i];
var o = r % 11
, u = e.substring(17);
return 2 == o ? "X" == u || "x" == u : u == n[o]
}
return !1
}