javascript验证18位带校验码的身份证
浏览(2434).NET/*身份证18位校验 json 2013-3-3*/
function CheckIdCardField(v_card) { var reg = /^\d{15}(\d{2}[0-9X])?$/i; if (!reg.test(v_card)) { return false; } var n = 0; var address = "11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91"; if (address.indexOf(v_card.substring(0, 2)) == -1) { return false; //省份验证 } var d = (v_card.substring(6, 10) + "-" + v_card.substring(10, 12) + "-" + v_card.substring(12, 14)); var newDate = new Date(Date.parse((d).replace(/-/g, "/"))); if (!newDate) { return false; //生日验证 } var arrVarifyCode = new Array("1", "0", "x", "9", "8", "7", "6", "5", "4", "3", "2"); var Wi = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); var sum = 0; for (var i = 0; i < 17; i++) { sum += parseInt(Wi[i]) * parseInt(v_card[i].toString()); } var y = sum % 11; if (arrVarifyCode[y] != v_card[17].toLowerCase()) { return false; //校验码验证 } return true; //符合GB11643-1999标准 }
标签: