身份证号码验证正确性

function idIdNum(val) {
var info = "请输入正确的身份证号";
if (!val || "string" != typeof val || 18 != val.length) return info;
val = val.toLowerCase();
var a = /(^\d{17}(\d|X)$)/i;
if (!a.test(val)) return u;
for (var t = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2], n = [1, 0, "x", 9, 8, 7, 6, 5,
4, 3, 2], e = 0, i = "", r = 0; r < val.length - 1; r++) e += parseInt(val.substr(r, 1), 10) * t[r];
return i = e % 11,
n[i] != val.substr(val.length - 1, 1) ? info: void 0
}
posted @ 2016-03-18 13:26  有间小屋在森林  阅读(360)  评论(0编辑  收藏  举报