The citizenship number consists of a six-digit address code, an eight-digit date of birth code, a three-digit sequence code and a one-digit verification code.
The first two digits of the address code represent the province, the middle two digits represent the city, and the last two digits represent the county
The sequence code represents the sequence number assigned to persons born in the same year, month, and day within the area identified by the same address code. The odd numbers of the order codes are assigned to men and even numbers are assigned to women.
The verification code is a verification code calculated based on the first seventeen digit codes and according to the verification code of ISO 7064:1983.MOD 11-2.
Calculation method of verification code:
1) Multiply the 17-digit number of the previous ID number by different coefficients, and the coefficients from the first digit to the seventeenth digit are: 7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2 ;
2) Add the result of multiplying these 17-digit numbers and coefficients, divide them by 11 to get the remainder;
4) The remainder can only have 11 numbers 0 1 2 3 4 5 6 7 8 9 10, and the number of the last ID card corresponding to each is 1 0 X 9 8 7 6 5 4 3 2.
The legality verification of ID number supports 15-digit and 18-digit ID number supports address encoding, date of birth, and verification digit verification.
The code copy is as follows:
<div style="padding:20px 40px;">
<h1 style="font-size:20px;color:#999;">Identity card query</h1>
<input type="text" placeholder="enter ID number" id="code">
<input type="button" value="query" id="btn">
<p id="home"><strong>Hometown:</strong><span></span></p>
<p id="birthday"><strong>Date of Birth:</strong><span></span></p>
<p id="sex"><strong>Gender:</strong><span></span></p>
</div>
<script type="text/javascript">
//Remove the string head and tail spaces
var home='',birthday='',sex='';
function trim(str) {
return str.replace(/^/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 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:"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)$/i.test(code)){
alert("Identity card number format error");
home='',birthday='',sex='';
return false;
}
if(!city[code.substring(0,2)]){
alert("Address encoding error");
home='',birthday='',sex='';
return false;
}
if(code.length == 18){ //The 18-bit ID card needs to verify the last check bit
var codeArr = code.split('');
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 ]; //Check bit
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[code.substring(0,2)];
//Birthday
birthday = code.substring(6,10)+'year'+code.substring(10,12)+'month'+code.substring(12,14)+'day';
//gender
if(code.length==15){
sex = code.substring(14,15)%2==0 ? 'Female':'Male';
}else if(code.length==18){
sex = code.substring(14,17)%2==0 ? 'Female':'Male';
}
}
//Output result
document.querySelector('#btn').onclick=function(){
var code=document.querySelector('#code').value;
IdentityCodeValid(code);
document.querySelector('#home span').innerHTML=home;
document.querySelector('#birthday span').innerHTML=birthday;
document.querySelector('#sex span').innerHTML=sex;
}
</script>
This article mainly reads relevant identity information based on the rules of citizen ID cards, which is very convenient and practical, and is recommended to everyone.