<div style="padding:20px 40px;">
<h1 style="font-size:20px;color:#999;">ID card query</h1>
<input type="text" placeholder="enter ID number" >
<input type="button" value="query" >
<p ><strong>Journal of the People's *:</strong><span></span></p>
<p ><strong>Date of birth:</strong><span></span></p>
<p ><strong>Sex Never mind:</strong><span></span></p>
</div>
<script type="text/javascript">
//Remove the beginning and end spaces of strings
var home='',birthday='',sex='';
function trim(str) {
return (/^\s*|\s*$/g, "");
}
//Verify the ID card
function IdentityCodeValid(code) {
code=trim(code);
var city={11:"Beijing",12:"Tianjin",13:"Hebei",14:"Shanxi",15:"Inner *",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:"*",71:"*",81:"*",82:"Macao"};
if(!code || !/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/(code)){
alert("Identity card number format error");
home='',birthday='',sex='';
return false;
}
if(!city[(0,2)]){
alert("Address encoding error");
home='',birthday='',sex='';
return false;
}
if( == 18){ //The 18-bit ID card needs to verify the last check bit
var codeArr = ('');
var factor = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ]; //Weighting factor �
var parity = [ 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 ];
var sum = 0;
for (var i = 0; i < 17; i++){
sum += codeArr[i] * factor[i];
}
if(parity[sum % 11] != codeArr[17]){
alert("Check bit error");
home='',birthday='',sex='';
return false;
}
}
//Province
home = city[(0,2)];
//Birthday
birthday = (6,10)+'year'+(10,12)+'month'+(12,14)+'day';
//gender
if(==15){
sex = (14,15)%2==0 ? 'Female':'Male';
}else if(==18){
sex = (14,17)%2==0 ? 'Female':'Male';
}
}
//Output result
('#btn').onclick=function(){
var code=('#code').value;
IdentityCodeValid(code);
('#home span').innerHTML=home;
('#birthday span').innerHTML=birthday;
('#sex span').innerHTML=sex;
}
</script>