标签:idc new str 海南 山东 内蒙古 javascrip 台湾 div
function checkidcard(str) { var temp = {}; if (id_cards.checkCard(str)) { temp.msg = ""; temp.statu = true; return temp; } else { temp.msg = "身份证号格式不正确"; temp.statu = false; return temp; } } //身份证号码 var id_cards = { cities: { 11: "北京", 12: "天津", 13: "河北", 14: "山西", 15: "内蒙古", 21: "辽宁", 22: "吉林", 23: "黑龙江", 31: "上海", 32: "江苏", 33: "浙江", 34: "安徽", 35: "福建", 36: "江西", 37: "山东", 41: "河南", 42: "湖北", 43: "湖南", 44: "广东", 45: "广西", 46: "海南", 50: "重庆", 51: "四川", 52: "贵州", 53: "云南", 54: "西藏", 61: "陕西", 62: "甘肃", 63: "青海", 64: "宁夏", 65: "新疆", 71: "台湾", 81: "香港", 82: "澳门", 91: "国外" }, checkCard: function(a) { return this.isCardNo(a) && this.checkProvince(a) && this.checkBirthday(a) && this.checkParity(a) }, isCardNo: function(a) { var b = /(^\d{15}$)|(^\d{17}(\d|X)$)/i; return b.test(a) }, checkProvince: function(a) { var b = a.substr(0, 2); return void 0 == this.cities[b] ? !1 : !0 }, checkBirthday: function(a) { var b = a.length; if ("15" == b) { var c = /^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/, d = a.match(c), e = d[2], f = d[3], g = d[4], h = new Date("19" + e + "/" + f + "/" + g); return this.verifyBirthday("19" + e, f, g, h) } if ("18" == b) { var i = /^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/i, d = a.match(i), e = d[2], f = d[3], g = d[4], h = new Date(e + "/" + f + "/" + g); return this.verifyBirthday(e, f, g, h) } return !1 }, checkParity: function(a) { var b = a.length; if ("18" == b) { var c, d, e = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2), f = new Array("1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"), g = 0; for (c = 0; 17 > c; c++) g += a.substr(c, 1) * e[c]; return d = f[g % 11], d == a.substr(17, 1).toUpperCase() ? !0 : !1 } return !0 }, verifyBirthday: function(a, b, c, d) { var e = new Date, f = e.getFullYear(); if (d.getFullYear() == a && d.getMonth() + 1 == b && d.getDate() == c) { var g = f - a; return g >= 0 && 120 >= g ? !0 : !1 } return !1 } };
标签:idc new str 海南 山东 内蒙古 javascrip 台湾 div
原文地址:http://www.cnblogs.com/kymming/p/6406991.html