Home  >  Article  >  Web Front-end  >  ID card verification method provided by jquery form verification framework (sample code)_jquery

ID card verification method provided by jquery form verification framework (sample code)_jquery

WBOY
WBOYOriginal
2016-05-16 17:06:571787browse
As shown below:
Copy the codeThe code is as follows:

var aCity ={11:"Beijing",12:"Tianjin",13:"Hebei",14:"Shanxi",15:"Inner Mongolia",
21:"Liaoning",22:"Jilin",23:" Heilongjiang",31:"Shanghai",32:"Jiangsu",33:"Zhejiang",
34:"Anhui",35:"Fujian",36:"Jiangxi",37:"Shandong",41: "Henan",42:"Hubei",
43:"Hunan",44:"Guangdong",45:"Guangxi",46:"Hainan",50:"Chongqing",51:"Sichuan"
,52:"Guizhou",53:"Yunnan",54:"Tibet",61:"Shaanxi",62:"Gansu",63:"Qinghai",
64:"Ningxia",65:" Xinjiang",71:"Taiwan",81:"Hong Kong",82:"Macau",91:"Overseas"}


function isCardID(sId){
var iSum=0;
var info="" ;
if(!/^d{17}(d|x)$/i.test(sId)) return "The length or format of the ID card you entered is wrong";
sId=sId.replace(/x$/i,"a");
if(aCity[parseInt(sId.substr(0,2))]==null) return "Your ID card region is illegal" ;
sBirthday=sId.substr(6,4) "-" Number(sId.substr(10,2)) "-" Number(sId.substr(12,2));
var d=new Date(sBirthday.replace(/-/g,"/")) ;
if(sBirthday!=(d.getFullYear() "-" (d.getMonth() 1) "-" d.getDate() ))return "The date of birth on the ID card is illegal";
for(var i = 17;i>=0;i --) iSum = (Math.pow(2,i) % 11) * parseInt(sId .charAt(17 - i),11) ;
if(iSum !=1) return "The ID number you entered is illegal";
return true;//aCity[parseInt(sId.substr(0 ,2))] "," sBirthday "," (sId.substr(16,1)%2?"Male":"Female")
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn