Identification number is legal, regional validation rules

Source: Internet
Author: User
<?php//birthday is needless to say, the number of the first 6 can be judged by the region//the first 17 digits multiplied by this 17 digit sum  divided by 11, the remainder is the last digit of the ID card (10=2,2=x) except for this two number $arr = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, ten, 5, 8, 4, 2]; $result = [0, 1,, 3, 4, 5, 6, 7, 8, 9, ' X ' =>2]; $code = Trim ($_get[' code ']); $count = 0;forea CH ($arr as $key = + $val) {    $num = substr ($code, $key, 1);    $count + = $num * $val;    if ($key = =)        $sex = $num;} $n = intval ($count%); $a = substr ($code,-1, 1); if (!in_array ($n, $result) | | array_flip ($result) [$n]! = Strtoupper ($a) {die    (' ID card not valid ');} if ($sex%2==0)    Echo ' gender female, '; else    echo ' sex male, '; echo ' legal ';? >



Identification number is legal, regional validation rules

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.