In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
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.
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.