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 = "密碼強度不夠!密碼組成規則 =(純數字,純字母,純特殊字符)"; } break; case PasswordStrength.Medium: Match m2 = new Regex(@"^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&*]+$)[a-zA-Z\d!@#$%^&*]+$").Match(value); if (!m2.Success) { success = false; msg = "密碼強度不夠!密碼組成規則 =(字母+數字,字母+特殊字符,數字+特殊字符)"; } 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 = "密碼強度不夠!密碼組成規則 =(字母+數字+特殊字符)"; } break; } return new { valid = success, message = success ? string.Empty : msg }; }
<script src="scripts/jquery-1.4.1.js" type="text/javascript"></script> <script language="javascript" type="text/javascript"> /** * 定義驗證各種格式類型的正則表達式對象 */ var Regexs = { email: (/^[0-9a-z][0-9a-z\-\_\.]+@([0-9a-z][0-9a-z\-]*\.)+[a-z]{2,}$/i),//郵箱 phone: (/^0[0-9]{2,3}[2-9][0-9]{6,7}$/), //座機手機號碼 ydphpne: (/^((13[4-9])|(15[012789])|147|182|187|188)[0-9]{8}$/),//移動手機號碼 allphpne: (/^((13[0-9])|(15[0-9])|(18[0-9]))[0-9]{8}$/),//所有手機號碼 ltphpne: (/^((13[0-2])|(15[56])|(186)|(145))[0-9]{8}$/),//聯通手機號碼 dxphpne: (/^((133)|(153)|(180)|(189))[0-9]{8}$/), //電信手機號碼 url: (/^http:\/\/([0-9a-z][0-9a-z\-]*\.)+[a-z]{2,}(:\d+)?\/[0-9a-z%\-_\/\.]+/i),//網址 num: (/[^0-9]/), //數字 cnum: (/[^0-9a-zA-Z_.-]/), photo: (/\.jpg$|\.jpeg$|\.gif$/i),//圖片格式 row: (/\n/ig) }; /** * @return 若符合對應的格式,返回true,否則返回false */ function chkFormat(str, ftype) { var nReg = Regexs[ftype]; if (str == null || str == "") return false; //輸入為空,認為是驗證通過 if (ftype == 'num') { if (!nReg.test(str) && !chkChinese(str)) {//10.23 tenfy 必須為數字且不能有中文 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>