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