Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of regular expressions for form validation

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the form verification regular expression example analysis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to know about it.

Verify:! reg.test (value)

Mailbox:

Reg = / ^\ w+ ((-\ w+) | (\.\ w+)) *\ @ [A-Za-z0-9] + ((\. | -) [A-Za-z0-9] +) *\. [A-Za-z0-9] + $/ I

Does not include Chinese:

Reg = /. * [\ u4e00 -\ u9fa5] +. * $/ I

ID number:

/ verify ID number: var city = {11 'Beijing', 12 'Tianjin', 13 'Hebei', 14 'Shanxi', 15 'Nei Mongol', 21 'Liaoning', 22 'Jilin', 23 'Heilongjiang', 31 'Shanghai', 32 'Jiangsu', 33 'Zhejiang', 34 'Anhui', 35 'Fujian', 36 'Jiangxi', 37 'Shandong', 41 'Henan' 42, 43, Hunan, 44, Guangdong, 45, Guangxi, 46, Hainan, Chongqing, 51, Guizhou, 53, Xizang, 61, Shaanxi, 62, Qinghai, 64, Ningxia, 65, Xinjiang, 71, Taiwan, 81, Hong Kong, Macao 91purl 'foreign'} Function check_idcard (n) {var im = 0; var info, I, bd; if (n.length! = 18) {return false;} n = n.replace (/ parseint (n.substr (0Mague 2))] = = null) {return false;} bd = n.substr (6jue 4) + "-" + Number (n.substr (10jue 2)) + "-" + Number (n.substr (12jue 2)) Var d = new Date (bd.replace (/-/ g, "/")) if (bd! = (d.getFullYear () + "-" + (d.getMonth () + 1) + "+ d.getDate ()) {return false;} for (I = 17; I > = 0; iMuk -) {im + = (Math.pow (2MagneI)% 11) * parseInt (n.charAt (17-I), 11)} if (im% 11! = 1) {return false;} return true;}

Password strength detection:

Function ops_pwd_set (obj) {var pwd = obj; if (typeof obj.value! = 'undefined') pwd = obj.value; if (pwd = =') return false; var len = pwd.length; if (pwd = =') {ops_show ("password cannot be empty", true); return false;} / / Chinese if (/ [\ u4e00 -\ u9fa5] + / .test (pwd)) {ops_show ("password cannot contain Chinese", true); return false } / / Blank var tmppwd = pwd.replace (/\ blank var tmppwd g, "); if (tmppwd! = pwd) {ops_show (" password cannot contain white space characters ", true); return false;} / / length if (len)

< 6 || len >

20) {ops_show ("password length should be between 6 and 20 digits", true); return false;} / / regular expression var is_all_num = / ^\ d+$/.test (pwd); var have_num = /\ d/.test (pwd); var is_all_abc = / ^ [a-zA-Z] + $/ .test (pwd); var have_abc = / [a-zA-Z] / .test (pwd) Var have_strong = / [^ a-zA-Z0-9] / .test (pwd); var is_very_strong = pwd.split (/ [^ a-zA-Z_0-9] /). Length > 2; / * * disabled: * 1) all digits and less than 8 digits * 2) password characters are all the same * / var disable_msg = "this password is too weak to be available"; if (is_all_num & len)

< 8){ ops_show(disable_msg,true); return false; } var i=0; var apwd = pwd.split(''); for(i=1; i < len ; i ++) if(apwd[i] != apwd[0]) break; if(i >

= len) {ops_show (disable_msg,true); return false;} / * * very strong: * 1) numbers and letters and other printable characters (greater than 2 bits) and greater than or equal to 8 digits * / if ((have_num & have_abc & & is_very_strong & & len > = 8) {ops_show ('very strong'); return true } / * * strong: * 1) numbers and letters and other printable characters greater than or equal to 8 digits * 2) numbers and letters and other printable characters (greater than 2 digits) and less than 8 digits * 3) pairwise combinations greater than or equal to 8 digits * / if ((have_num & & have_abc & & have_strong & & len > = 8) | | (have_num & have_abc & is_very_strong & len)

< 8) || ( ( (have_num && have_strong) || (have_abc && have_strong) ) && len >

= 8)) {ops_show ('strong'); return true } / * in: * 1) mixed numbers and letters and greater than or equal to 8 digits * 2) numbers and letters and other printable characters and less than 8 digits * 3) pairwise combination * / if ((have_num & & have_abc & & len > = 8) | (have_num & & have_abc & & have_strong & & len < 8) | (have_num & have_strong) | | (have_abc & & have_strong)) {ops_show ('password strength') Return true;} / * * weak: * 1) all numbers or letters * 2) numbers mixed with letters and less than 8 digits * / if ((is_all_num | | is_all_abc) | | (have_num & & have_abc & & len < 8) {ops_show ('weak password strength'); return true;} / / other ops_show ('average password strength'); return true } Thank you for reading this article carefully. I hope the article "sample Analysis of form validation regular expressions" shared by the editor will be helpful to you. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report