For a regular expression, if the number of numbers is 1, it can be matched. if the number is greater than 1, it cannot be matched.

Source: Internet
Author: User
For a regular expression, the number of numbers can be matched by 1, and the number of numbers that are greater than 1 cannot be matched. The regular expression is as follows: $ patten = '/^ [1-9] \ d {5} [1-2] \ d {3} (0 \ d) | (1 [0-2]) ([0 | 1 | 2] \ d) | 3 [0-1]) \ d {4} $ /'; // This is the last 4. if we change the last 4 to 1, we can match a regular expression. the number of numbers can be matched if we write 1, if the write size is greater than 1, the matching fails.
The regular expression is as follows:

$ Patten = '/^ [1-9] \ d {5} [1-2] \ d {3} (0 \ d) | (1 [0-2]) ([0 | 1 | 2] \ d) | 3 [0-1]) \ d {4} $ /'; // the last 4


If you change the last 4 to 1, the matching will fail.

This regular expression is used to match the ID card number. if any of you have such a regular expression, you can refer to it for reference ~ Compatible with 15-bit and 18-bit ~
------ Solution --------------------
1. ID card number meaning:
Generation 1 (now obsolete, no need to judge)
Region Code (6 digits) year of birth (2 digits) month of birth (2 digits) day of birth (2 digits) plus (3 digits) 15 digits in Total
Second generation
Region Code (6 digits) year of birth (4 digits) year of birth (2 digits) day of birth (2 digits) plus (3 digits) check (1 digit) total 18 digits
The check bit may be X
2. simple determination. you only need to determine whether the number of digits is correct.
/^ \ D {15 }(? : \ D {2} [\ dX])? $/
3. exact determination (second generation) should use the verification code generation algorithm. The "ID card verification code generation function" in various languages can be found online

------ Solution --------------------
Validateidnumber ("22111111111234563 ");

If the string is used, the value is out of the range.
Originally, the ID card number should be a string

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.