C# 判斷是否英文或數字:
Regex reg = new Regex(@"^[A-Za-z0-9]+$");<br />return reg.IsMatch(passwd);
Javascript檢測密碼字串強度:
int intScore = 0;<br /> if (passwd.match(/[a-z]/))<br /> {<br /> intScore = (intScore+1)<br /> } if (passwd.match(/[A-Z]/))<br /> {<br /> intScore = (intScore+5)<br /> }<br /> if (passwd.match(//d+/))<br /> {<br /> intScore = (intScore+5)<br /> } if (passwd.match(/(/d.*/d.*/d)/))<br /> {<br /> intScore = (intScore+5)<br /> }<br /> if (passwd.match(/[!,@#$%^&*?_~]/))<br /> {<br /> intScore = (intScore+5)<br /> } if (passwd.match(/([!,@#$%^&*?_~].*[!,@#$%^&*?_~])/))<br /> {<br /> intScore = (intScore+5)<br /> }<br /> if (passwd.match(/[a-z]/) && passwd.match(/[A-Z]/))<br /> {<br /> intScore = (intScore+2)<br /> }<br /> if (passwd.match(//d/) && passwd.match(//D/)) // [verified] both letters and numbers<br /> {<br /> intScore = (intScore+2)<br /> }<br /> if (passwd.match(/[a-z]/) && passwd.match(/[A-Z]/) && passwd.match(//d/) && passwd.match(/[!,@#$%^&*?_~]/))<br /> {<br /> intScore = (intScore+2)<br /> }<br /> return intScore;