Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to verify the second generation ID card number by using regular expression

Shulou Source: shulou.com Published: 2022-06-02 11:22:11 10月02日 Update

Today, I will talk to you about how to use regular expressions to verify the second-generation ID card numbers, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.

IdCodeValid:function (code) {/ / ID card number legitimacy verification / / support 15-bit and 18-bit ID card number / / support address code, date of birth, check bit verification var city= {11: "Beijing", 12: "Tianjin", 13: "Hebei", 14: "Shanxi", 15: "Inner Mongolia", 21: "Liaoning", 22: "Jilin", 23: "Heilongjiang", 31: "Shanghai", 32: "Jiangsu" 33: "Zhejiang", 34: "Anhui", 35: "Fujian", 36: "Jiangxi", 37: "Shandong", 41: "Henan", 42: "Hubei", 43: "Hunan", 44: "Guangdong", 45: "Guangxi", 46: "Hainan", 50: "Chongqing", 51: "Sichuan", 52: "Guizhou", 53: "Yunnan", 54: "Xizang", 61: "Shaanxi", 62: Gansu " 63: Qinghai, 64: Ningxia, 65: Xinjiang, 71: Taiwan, 81: Hong Kong, 82: Macao, 91: abroad} Var row= {'pass':true,' msg':' Verification successful'}; if (! code | |! / ^\ d {6} (18 | 19 | 20)?\ d {2} (0 [1-9] | 1 [012]) (0 [1-9] | [12]\ d | 3 [01])\ d {3} (\ d | [xX]) $/ .test (code)) {row= {'pass':false,' msg':' ID number format error'} } else if (! city [code.substr (0Power2)]) {row= {'pass':false,' msg':' ID address coding error'};} else {/ / 18-bit ID card needs to verify the last check bit if (code.length = = 18) {code = code.split ('') / / ∑ (ai × Wi) (mod 11) / / weighting factor var factor = [7, 9, 10, 5, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]; / / check bit var parity = [1, 0,'X-ray, 9, 8, 7, 6, 5, 4, 3, 2]; var sum = 0; var ai = 0; var wi = 0; for (var I = 0; I < 17) ISuppli +) {ai = code [I]; wi = factor [I]; sum + = ai * wi;} if (parity [sum% 11]! = code [17] .toUpperCase ()) {row= {'pass':false,' msg':' ID number check bit error'};} return row;} IdCodeValid ('xxx')

Regular expression:

Date of birth 1800-2099 (18 | 19 | 20)?\ d {2} (0 [1-9] | 1 [012]) (0 [1-9] | [12]\ d | 3 [01])

ID card regular expression / ^\ d {6} (18 | 19 | 20)?\ d {2} (0 [1-9] | 1 [012]) (0 [1-9] | [12]\ d | 3 [01])\ d {3} (\ d | [xX]) $/

Bit check rule 6-bit address code + 8-bit date of birth + 3-bit sequence number + 1-bit check bit

After reading the above, do you have any further understanding of how to use regular expressions to verify second-generation ID numbers? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Tags: Identity authentication certificate number regular expression ID card content address date code support number second generation error dislocation sequence number black dragon Yunnan Inner Mongolia Inner Mongolia Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MariaDB Apple Linux MySQL