1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| var idCardArea = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '北京', '天津', '河北', '山西', '内蒙古', 0, 0, 0, 0, 0, '辽宁', '吉林', '黑龙江', 0, 0, 0, 0, 0, 0, 0, '上海', '江苏', '浙江', '安微', '福建', '江西', '山东', 0, 0, 0, '河南', '湖北', '湖南', '广东', '广西', '海南', 0, 0, 0, '重庆', '四川', '贵州', '云南', '西藏', 0, 0, 0, 0, 0, 0, '陕西', '甘肃', '青海', '宁夏', '新疆', 0, 0, 0, 0, 0, '台湾', 0, 0, 0, 0, 0, 0, 0, 0, 0, '香港', '澳门', 0, 0, 0, 0, 0, 0, 0, 0, '国外']
var idCardValid1 = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
var idCardValid2 = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']
var province = parseInt(value.substr(0, 2), 10);
var city = parseInt(value.substr(2, 2), 10);
var area = parseInt(value.substr(4, 2), 10); var year, month, day; if (idCardArea[province] != void 0 && idCardArea[province] != 0) { if (value.length == 15) { year = parseInt('19' + value.substr(6, 2), 10); month = parseInt(value.substr(8, 2), 10) - 1; day = parseInt(value.substr(10, 2), 10); } else if (value.length == 18) { year = parseInt(value.substr(6, 4), 10); month = parseInt(value.substr(10, 2), 10) - 1; day = parseInt(value.substr(12, 2), 10); var sum = 0; for (var k = 0; k < 17; k++) { sum += parseInt(value[k], 10) * idCardValid1[k]; } var mod = sum % 11; if (mod == 2) { isval = value[17] == 'x' || value[17] == 'X'; } else { isval = value[17] == idCardValid2[9][mod]; } } var thedate = new Date(year, month, day); if (thedate.getFullYear() != year || thedate.getMonth() != month || thedate.getDate() != day) { isval = false; } }
|