Php ID number check instance

Source: Internet
Author: User
This article mainly introduces the php ID card number check class, which involves php Regular Expression matching and array traversal related skills. For more information, see

This article mainly introduces the php ID card number check class, which involves php Regular Expression matching and array traversal related skills. For more information, see

This example describes the php ID card number check class. Share it with you for your reference. The details are as follows:

<? Php class CIDMaker // declare an id card number check class {var $ id; var $ err; var $ idx = array,, 3,); var $ idy = array, ,); function check ($ id_no) {$ id_no = ucfirst ($ id_no ); // convert uppercase letters if (ereg ("^ [A-Z] [0-9] {9} $", $ id_no) {for ($ I = 0; $ I <10; $ I ++) $ ch [$ I] = substr ($ id_no, $ I, 1); $ I = 0; // convert English letters into numbers BEGINfor ($ char = "A"; $ char! = $ Ch [0]; $ char ++) $ I ++; // convert English letters to numbers END // import check formula BEGIN $ id = $ this-> idx [$ I] + $ this-> idy [$ I] * 9 + $ ch [1] * 8 + $ ch [2] * 7 + $ ch [3] * 6 + $ ch [4] * 5 + $ ch [5] * 4 + $ ch [6] * 3 + $ ch [7] * 2 + $ ch [8] * 1 + $ ch [9] * 1; $ id = ($ id % 10) = 0 )? TRUE: FALSE; return $ id; // import check formula END} elsereturn 0 ;}}?>

I hope this article will help you with php programming.

,

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.