function isIDCard(obj) { var aCity = { 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: "国 外" }; var iSum = 0; var strIDno = obj; var idCardLength = strIDno.length; if (!/^\d{17}(\d|x)$/i.test(strIDno) && !/^\d{15}$/i.test(strIDno)) { layer.alert(‘输入的身份证号长度不对,或者号码不符合规定<br>15位号码应全为数字,18位号码末位可以为数字或X‘,{icon:2}); return false; } if (aCity[parseInt(strIDno.substr(0, 2))] == null) { layer.alert(‘无效身份证号码,请确认‘,{icon:2}); return false;// 非法地区 } // 15位身份证转换为18位 if (idCardLength == 15) { sBirthday = "19" + strIDno.substr(6, 2) + "-" + Number(strIDno.substr(8, 2)) + "-" + Number(strIDno.substr(10, 2)); var d = new Date(sBirthday.replace(/-/g, "/")) var dd = d.getFullYear().toString() + "-" + (d.getMonth() + 1) + "-" + d.getDate(); if (sBirthday != dd) { layer.alert(‘身份证号码格式输入错误,生日错误‘,{icon:2}); return false; //非法生日 } strIDno = strIDno.substring(0, 6) + "19" + strIDno.substring(6, 15); strIDno = strIDno + GetVerifyBit(strIDno); } // 判断是否大于2078年,小于1900年 var year = strIDno.substring(6, 10); if (year < 1900 || year > 2078) { layer.alert(‘身份证号码格式输入错误,年份错误‘,{icon:2}); return false;//非法生日 } //18位身份证处理 //在后面的运算中x相当于数字10,所以转换成a strIDno = strIDno.replace(/x$/i, "a"); sBirthday = strIDno.substr(6, 4) + "-" + Number(strIDno.substr(10, 2)) + "-" + Number(strIDno.substr(12, 2)); var d = new Date(sBirthday.replace(/-/g, "/")) if (sBirthday != (d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate())) { layer.alert(‘身份证号码格式输入错误,生日错误‘,{icon:2}); return false; //非法生日 } // 身份证编码规范验证 for (var i = 17; i >= 0; i --) iSum += (Math.pow(2, i) % 11) * parseInt(strIDno.charAt(17 - i), 11); if (iSum % 11 != 1) { layer.alert(‘身份证号码无效,请确认‘,{icon:2}); return false;// 非法身份证号 } // 判断是否屏蔽身份证 var words = new Array(); words = new Array("11111119111111111", "12121219121212121"); for (var k = 0; k < words.length; k++) { if (strIDno.indexOf(words[k]) != -1) { return false; } } //return true; }