C#正则表达式检测字符串(密码强度)

C# 判断是否英文或数字:

Regex reg = new Regex(@"^[A-Za-z0-9]+$"); return reg.IsMatch(passwd);

 

Javascript检测密码字符串强度:

int intScore = 0; if (passwd.match(/[a-z]/)) { intScore = (intScore+1) } if (passwd.match(/[A-Z]/)) { intScore = (intScore+5) } if (passwd.match(//d+/)) { intScore = (intScore+5) } if (passwd.match(/(/d.*/d.*/d)/)) { intScore = (intScore+5) } if (passwd.match(/[!,@#$%^&*?_~]/)) { intScore = (intScore+5) } if (passwd.match(/([!,@#$%^&*?_~].*[!,@#$%^&*?_~])/)) { intScore = (intScore+5) } if (passwd.match(/[a-z]/) && passwd.match(/[A-Z]/)) { intScore = (intScore+2) } if (passwd.match(//d/) && passwd.match(//D/)) // [verified] both letters and numbers { intScore = (intScore+2) } if (passwd.match(/[a-z]/) && passwd.match(/[A-Z]/) && passwd.match(//d/) && passwd.match(/[!,@#$%^&*?_~]/)) { intScore = (intScore+2) } return intScore;

你可能感兴趣的:(Visual,C#)