In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
During the test, many students are not very clear about the regular expression of the identity * number in the program written by java, so I will write a blog post to explain it.
First, understand the coding rules of the identity * number, and then write the regular expression according to the coding rules:
The coding rules for 18-bit identity * numbers are as follows:
Bits 1 and 2: codes of provinces, autonomous regions and municipalities directly under the Central Government (for more information, please see the code table)
3rd and 4th: prefecture-level city, league, autonomous prefecture code (for more information, please see the code table)
5th and 6th: County, county city, district code (for more information, please see the code table)
7th to 10th: year of birth
11th and 12th: month of birth
13th and 14th: birthdays
15th to 17th: sequence code, 17th is odd for boys and even for girls (you can verify it for yourself)
Bit 18: indicates the check code, which can be 0-9 or X (note that it is uppercase)
So the regular expression for verifying an 18-digit identity * number is:
"^ [1-9]\ d {5} [1-9]\ d {3} ((0 [1-9]) | | (1 [0-2])) ((0 [1-9])) | | (1\ d) | | (3 [0-1]))\\ d {3} ([0-9] | X) $"
Where:
1. ^ means the beginning, and $means the end
2. The first six digits: [1-9] the first digit is 1-9, followed by 5 random numbers of 0-9 ({5} means five digits)
3. Year: [1-9]\\ d {3} indicates that the year is 1-9 plus three random numbers from 0-9, for example, 1994
April: (0 [1-9]) | | (1 [0-2])) indicates that the month is 01-09 or 10-12 of the two digits
5. Day: (0 [1-9]) | | (1\ d) | | (2\ d) | | (3 [0-1])) indicates 01-09 or 10-19 or 20-29 or 30-31
6. The last four digits:\ d {3} ([0-9] | | X) represents a random number of 3 digits 0-9 plus one of 0-9 or X.
However, the identity * number verified by the above regular expression can only be said to be in line with the coding rules, and it is not possible to determine whether it is valid or not. Because even the above regular expression can not avoid the situation of February 31, in addition, the check code for the last bit is calculated according to the specific formula, not random. But for the current general project, this regular expression is already a more rigorous one.
Add: the 15-digit identity * number is no longer used, but the regular expression of the 15-digit identity * 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} $"
Description: 15 bits × × × year of birth displays two digits, for example, born in 1994, 18 bits × × shows 1994, while 15 bits displays 94, and the other 15 bits have no check code, so the overall number is 3 digits less than the 18-bit identity * number.
The algorithm for determining the last bit of the check code with the-× × sign is:
1. Multiply the first 17 digits of the identity * by different coefficients. The coefficients from the first to the 17th are:
7 Mui 9 Mui 10 Mui 5 Mui 8 Mui 4 Mui 2 Mui 6 Mui 6 Mui 7 Mui 9 Mui 10 Mui 8 Mui 4 Mui 2
2. Add the 17 digits to the result of multiplying the coefficients, add them and divide them by 11 to determine the remainder.
3. The remainder can only have the 11 digits of 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, and the last digit corresponding to them is 1-0-X-9-8-7-6-5-4-3-2.
You can try to test it yourself to see if you can derive the last check code from the first 17 digits of your identity number.
For more courses for instructors, please visit http://edu.51cto.com/lecturer/5811414.html
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.