Regular expression for identity * in Java

Source: Internet
Author: User

Many students are not very clear about the regular expression of the identity * number in the program written by Java during the test, so we write a blog post explaining it.


first you need to understand the coding rules of the identity * number and then write the regular expression according to the coding rules:


The 18-bit identity * Code rules are as follows:

1th and 2nd digits: Province, autonomous Region, municipality code (for values to view the Code table);

3rd and 4th place: prefecture-level, AU, Autonomous Prefecture code (for values to view the Code table);

5th and 6th: counties, county-level, district code (for values to view the Code table);

7th to 10th place: year of birth;

11th and 12th place: birth month;

13th and 14th place: birthday;

15th to 17th: Sequential code, 17th digit If the male is singular, if the girl is even (you can verify it yourself);

18th bit: Indicates the check code, can be 0-9 or x ( note is uppercase );


So the regular expression to verify the 18-bit identity * number is:

"^[1-9]\\\\d{5}[1-9]\\\\d{3} ((0[1-9]) | | (1[0-2])) ((0[1-9]) | | (1\\\\d) | | (2\\\\d) | | (3[0-1])) \\\\d{3} ([0-9]| | X) $ "

which

1. ^ Indicates the beginning,$ means end;

2, the first six bits: [1-9] The first bit is 1-9 of them, followed by 0-9 random number 5 ({5} means five-digit meaning );

3. Year: [1-9]\\\\d{3} indicates that the year is 1-9 start plus 0-9 random number three, for example 1994;

4. Month: ((0[1-9]) | | (1[0-2])) Indicates that the month is a two-digit number of 01-09 or 10-12;

5, Day: ((0[1-9]) | | (1\\\\d) | | (2\\\\d) | | (3[0-1])) Represents 01-09 or 10-19 or 20-29 or 30-31 of the two-digit number;

6. Last four bits:\\\\d{3} ([0-9]| | X) indicates a 3-bit 0-9 random number plus 0-9 one or x;


However, the above regular expression verification of the identity * Number can only be said to comply with the ID code rules, can not determine whether the identity card is valid. Because even though the regular expression above still cannot avoid the occurrence of February 31, in addition, for the last check code is calculated according to the specific formula, not random. But for the current general project, this regular expression is a more rigorous one.

Add: The 15-bit ID number is no longer used, but the regular expression for the 15-bit ID * Number is also supplemented for your reference:

"^[1-9]\\\\d{7} ((0[1-9]) | | (1[0-2])) ((0[1-9]) | | (1\\\\d) | | (2\\\\d) | | (3[0-1])) \\\\d{3}$ "

Note: 15-digit ID card year of birth shows two, for example, 1994 births, 18 ID card display 1994, while 15 digits display 94, and 15 ID card without parity code, so the overall than 18 digits * Number 3 bits less.


Attached-identification number of the last check code to determine the algorithm is:

1. Multiply the first 17 digits of the status * number by the different coefficients respectively. The coefficients from the first bit to the 17th position are:
7-9-10-5-8-4-2-1-6-3-7-9-10-5-8-4-2;
2. Add the result of multiplying the 17 digits and the coefficients by adding and dividing by 11 to determine the remainder;
3, the remainder only may have the 0-1-2-3-4-5-6-7-8-9-10 these 11 numbers, the corresponding last ID card number is 1-0-x-9-8-7-6-5-4-3-2 respectively.
You can try it yourself and see if the last Test code can be deduced from the first 17 digits of your identity * number.


For more lectures, please visit:http://edu.51cto.com/lecturer/5811414.html



This article from "Hao Yang _ Habitat" blog, please be sure to keep this source http://zdytesting.blog.51cto.com/5811414/1946771

Identity * Regular expression in Java

Related Article

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.