Structure of the ID card number
The ID card number is a characteristic combination code, which consists of a 17 digit ontology code and a check code.
Order from left to right according to this: six-digit address code, eight-digit birth date code, three-digit sequential code and a digital parity code.
Address code (top six digits)
The administrative division code of the county (city, Flag, district) of the resident account of the encoding object is executed according to the GB/T2260 regulations.
Birth date code (seventh to 14 digits)
Indicates the year, month, and day of the encoding object's birth, which is executed according to gb/t7408, and the year, month, and day codes are not separated by delimiters.
Order code (15th to 17 digits)
indicating the range of areas identified by the same address code, the order number of the person born in the same year, the same month, the same day, and the odd distribution of the order code to men, even to women.
Parity code (18th digits)
1.17-bit Digital ontology code weighted summation formula
s= sum (Ai * Wi), i=0, ..., 16, the first 17 digits of the right sum.
Ai: Indicates the ID number value of position I
Wi: A weighted factor representing position I
Wi:7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4-2
2. Calculation mode
Y = mod (S, 11)
3. Through the model to obtain the corresponding check code
Y:0 1 2 3 4 5 6 7 8 9 10
Check code: 1 0 X 9 8 7 6 5 4 3 2
Verify ID number method:
<?php
function Checkidcard ($idcard) {
//can only be 18-bit
if (strlen ($idcard)!=18) {return
false;
}
Remove the body code
$idcard _base = substr ($idcard, 0);
Remove the check code
$verify _code = substr ($idcard, 1);
Weighted factor
$factor = Array (7, 9, 5, 8, 4, 2, 1, 6, 3, 7, 9, ten, 5, 8, 4, 2);
Check code corresponds to the value
$verify _code_list = Array (' 1 ', ' 0 ', ' X ', ' 9 ', ' 8 ', ' 7 ', ' 6 ', ' 5 ', ' 4 ', ' 3 ', ' 2 ');
Check code $total = 0 According to the first 17 digits
;
For ($i =0 $i <17; $i + +) {
$total + = substr ($idcard _base, $i, 1) * $factor [$i];
}
modulo
$mod = $total%;
Compare checksum code
if ($verify _code = = $verify _code_list[$mod]) {return
true;
} else{return
false;
}
$idcard = ' Fill in the ID number to be validated here ';
Var_dump (Checkidcard ($idcard));
>
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/PHP/