The perfect 18-digit ID number for regular expressions

Source: Internet
Author: User

Match the 18-bit ID number and the regular expression is as follows:

/^[1-9][0-9]{5} (19|20) [0-9]{2} ((01|03|05|07|08|10|12) (0[1-9]|[ 1-2][0-9]|31) | (04|06|09|11) (0[1-9]| [1-2] [0-9]|30] |02 (0[1-9]|[ 1-2][0-9])) [0-9]{3} ([0-9]|x| X) $/

Note: Now the ID number is already 18, there is no need to consider matching 15 bit.

18-digit ID Number: 6-digit area + 4-year + 4-month-day + 3-digit + 1-bit new generation number

Logic:

1) 6-digit area number: First non-0, after five digits. corresponding regular: [1-9][0-9]{5}

2) 4-digit year: 19 or 20 starts with the post two digits. Corresponding Regular: (19|20) [0-9]{2}

3) 4-Month Day:

i) Otsuki 31 days. Corresponding Regular: (01|03|05|07|08|10|12) (0[1-9]|[ 1-2][0-9]|31)

II) Xiao Yue for 30 days. Corresponding Regular: (04|06|09|11) (0[1-9]|[ 1-2][0-9]|30)

III) February 28 days or 29 days. corresponding Regular: 02 (0[1-9]|[ 1-2][0-9])

4) 3-digit number: three-digit number. corresponding regular: [0-9]{3}

5) 1-bit new generation number: number or X. corresponding Regular: ([0-9]|x| X

The perfect regular still has its drawbacks:

1) Unmatched leap year

2) does not match the presence of the first three-digit region number

The perfect 18-digit ID number for regular expressions

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.