javascript验证身份证完全方法具体实现
人气:0复制代码 代码如下:
var certCardValid = function(id){
var arrVerifyCode = [1,0,"x",9,8,7,6,5,4,3,2];
var wi = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2];
var Checker = [1,9,8,7,6,5,4,3,2,1,1];
var msg = "";
if(id.length != 15 && id.length != 18) {
Ext.MessageBox.alert("信息提示","SFZ号共有15位或18位。");
return false;
}
var ai = id.length == 18 ? id.substring(0,17) : id.slice(0,6) + "19" + id.slice(6,16);
if (!/^https://img.qb5200.com/download-x/d+$/.test(ai)) {
Ext.MessageBox.alert("信息提示","SFZ除最后一位外,必须为数字。");
return false;
}
var yyyy = ai.slice(6,10);
var mm = ai.slice(10,12)-1;
var dd = ai.slice(12,14);
var d = new Date(yyyy,mm,dd);
var now = new Date();
var year = d.getFullYear();
var mon = d.getMonth();
var day = d.getDate();
if (year != yyyy || mon != mm || day != dd) {
Ext.MessageBox.alert("信息提示","SFZ无效。");
return false;
}
for(var i = 0,ret = 0; i < 17; i++){
ret += ai.charAt(i) * wi[i];
}
ai += arrVerifyCode[ret %= 11];
ai = ai.toUpperCase();
if(id.length == 18 && id != ai){
Ext.MessageBox.alert("信息提示","SFZ无效。");
return false;
}
return true;
};
加载全部内容