A regular expression of the related problems, the number of digits 1 can be matched, write than 1 of the match is not

Source: Internet
Author: User
A regular expression of the problem, the number of digits to write 1 can be matched on, write than 1 of the big match is not.
The regular 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 you change the last 4 to 1, you can match it and change it to 1.

This regular is to be used to match the ID card number, if any hero has the hope to be able to send out for reference ~ compatible with 15-bit and 18-bit ~


------Solution--------------------
1, the identity card number meaning:
Generation (now obsolete, no need to judge)
Area code (6-bit) birth year (2-digit) birth month (2-bit) birthday (2-bit) Shun (3-bit) total 15-bit
Second generation
Area code (6-bit) birth year (4-digit) birth month (2-bit) birthday (2-bit) Shun (3-bit) check digit (1-bit) total 18-bit
The check digit may be X
2, simple judgment, just determine whether the number of digits is correct
/^\D{15} (?: \ D{2}[\DX])? $/
3, the accurate determination (second generation) should use the check code generation algorithm. "ID Check code generation function" can be found on the Internet in various languages.

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

The string, the value of the word is out of bounds
The original ID 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.