Posted in Javascript onNovember 18, 2013
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("信息提示","身份证号共有15位或18位。"); return false; } var ai = id.length == 18 ? id.substring(0,17) : id.slice(0,6) + "19" + id.slice(6,16); if (!/^/d+$/.test(ai)) { Ext.MessageBox.alert("信息提示","身份证除最后一位外,必须为数字。"); 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("信息提示","身份证无效。"); 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("信息提示","身份证无效。"); return false; } return true; };
javascript验证身份证完全方法具体实现
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@