Common Regular Expressions and usage, regular expression usage
1. Verify the registration password strength at registration:
Public object IsValidPasswordStrength (string id, string value) {bool success = true; string msg = string. empty; switch (SysGlobalInfo. passwordStrength) {case PasswordStrength. low: Match m1 = new Regex (@ "^ (?: \ D + | [a-zA-Z] + | [! @ # $ % ^ & *] +) $ "). Match (value); if (! M1.Success) {success = false; msg = "insufficient password strength! Password composition rules = (pure numbers, pure letters, pure special characters) ";}break; case PasswordStrength. Medium: Match m2 = new Regex (@" ^ (?! [A-zA-z] + $ )(?! \ D + $ )(?! [! @ # $ % ^ & *] + $) [A-zA-Z \ d! @ # $ % ^ & *] + $ "). Match (value); if (! M2.Success) {success = false; msg = "insufficient password strength! Password composition rules = (letters + numbers, letters + special characters, numbers + special characters) ";}break; case PasswordStrength. high: Match m3 = new Regex (@ "^ (?! [A-zA-z] + $ )(?! \ D + $ )(?! [! @ # $ % ^ & *] + $ )(?! [A-zA-z \ d] + $ )(?! [A-zA-z! @ # $ % ^ & *] + $ )(?! [\ D! @ # $ % ^ & *] + $) [A-zA-Z \ d! @ # $ % ^ & *] + $ "). Match (value); if (! M3.Success) {success = false; msg = "insufficient password strength! Password composition rules = (letters + numbers + special characters) ";} break;} return new {valid = success, message = success? String. Empty: msg };}
2. Common Regular Expressions
<Script src = "scripts/jquery-1.4.1.js" type = "text/javascript"> </script> <script language = "javascript" type = "text/javascript"> /*** define the regular expression object */var Regexs = {email: (/^ [0-9a-z] [0-9a-z \-\ _ \.] + @ ([0-9a-z] [0-9a-z \-] * \.) + [a-z] {2, }$/I), // email phone: (/^ 0 [0-9] {2, 3} [2-9] [0-9] {6, 7} $/), // landline mobile phone number ydphpne: (/^ (13 [4-9]) | (15 [012789]) | 147 | 182 | 187 | 188) [0-9] {8} $ /), // mobile phone number allphpne: (/^ (13 [0-9]) | (15 [0-9]) | (18 [0-9]) [0-9] {8 }$/), // all mobile phone numbers ltphpne: (/^ (13 [0-2]) | (15 [56]) | (186) | (145) [0-9] {8} $ /), // China Unicom mobile phone number dxphpne: (/^ (133) | (153) | (180) | (189) [0-9] {8} $ /), // China Telecom mobile phone number url: (/^ http: \// \/([0-9a-z] [0-9a-z \-] * \.) + [a-z] {2,} (: \ d + )? \/[0-9a-z % \-_ \/\.] +/I), // URL num: (/[^ 0-9]/), // number cnum: (/[^ 0-9a-zA-Z _. -]/), photo :(/\. jpg $ | \. jpeg $ | \. gif $/I), // image format row: (/\ n/ig)};/*** @ return returns true if it meets the corresponding format, otherwise, false */function chkFormat (str, ftype) {var nReg = Regexs [ftype]; if (str = null | str = "") return false; // The input is null and is considered to pass if (ftype = 'num') {if (! NReg. test (str )&&! ChkChinese (str) {// 10.23 tenfy must be a number and cannot contain Chinese return true;} else {return false ;}} if (! NReg. test (str) {return true;} else {return false ;}}; function chkChinese (s) {for (var I = 0; I <s. length; I ++) {if (s. charCodeAt (I)> 255) return true;} return false ;}; </script>