Php extracts the birthday date from the ID card number and verifies whether it is an adult.

Source: Internet
Author: User
This article uses php technology to extract the birthday date in the ID card number to determine whether it is a function of a minor. The following code is a function used to extract the birthday date in the ID card number and determine whether the ID card number is an adult. You can determine the ID card of 15 and 18 digits at the same time. it is very useful after my own test. the Function code is as follows:

<? Php // use php to extract the birthday from the ID card, including the bit and bit ID card function getIDCardInfo ($ IDCard) {$ result ['error'] =; // Unknown error ,: incorrect ID card format: no error $ result ['flag'] = ''; // indicates the adult, indicating the minor $ result ['tdate'] =''; // birthday, format: -- if (! Eregi ("^ [-] ([-a-zA-Z] {}| [-a-zA-Z] {}) $", $ IDCard )) {$ result ['error'] =; return $ result;} else {if (strlen ($ IDCard) =) {$ tyear = intval (substr ($ IDCard,); $ tmonth = intval (substr ($ IDCard ,,)); $ tday = intval (substr ($ IDCard,); if ($ tyear> date ("Y") | $ tyear <(date ("Y ")-)) {$ flag =;} elseif ($ tmonth <| $ tmonth>) {$ flag =;} elseif ($ tday <| $ tday>) {$ flag = ;} else {$ tdate = $ tyear. "-". $ tmonth. "-". $ tday. ":"; if (time ()-mktime (, $ tmonth, $ tday, $ tyear)> *****) {$ flag = ;} else {$ flag =;}} elseif (strlen ($ IDCard) ==) {$ tyear = intval ("". substr ($ IDCard,); $ tmonth = intval (substr ($ IDCard,); $ tday = intval (substr ($ IDCard ,,)); if ($ tyear> date ("Y") | $ tyear <(date ("Y")-) {$ flag = ;} elseif ($ tmonth <| $ tmonth>) {$ flag =;} elseif ($ tday <| $ tday>) {$ flag = ;} else {$ tdate = $ tyear. "-". $ tmonth. "-". $ tday. ":"; if (time ()-mktime (, $ tmonth, $ tday, $ tyear)> *****) {$ flag = ;} else {$ flag =;}}}$ result ['error'] =; // Unknown error: incorrect ID card format ,: no error $ result ['isadresult'] = $ flag; // indicates the adult, indicating the minor $ result ['birthday'] = $ tdate; // return $ result on the birthday date ;}

The usage is as follows:

The code is as follows:


GetIDCardInfo ('ID card number ');


The above code is a php function used to extract the birthday date in the ID card number and verify whether it is an adult.

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.