Created
October 25, 2013 08:18
-
-
Save yangjunjun/7151248 to your computer and use it in GitHub Desktop.
测试密码强度
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 测试密码强度 | |
* | |
* 1.密码长度为[6-16]位,可以包含数字、字母、特殊符号 | |
* 2.当密码含有一种类型(数字、字母、特殊符号),且长度小于8时,强度为弱;长度大于8时强度为中; | |
* 3.当密码含有一种类型(数字、字母、特殊符号),且长度小于8时,强度为弱;长度大于8时强度为中; | |
*/ | |
function verifyPassword(val){ | |
val = val.trim(); | |
var l = val.length; | |
var i = 0; | |
var result = 0; | |
var regNum =/[0-9]/; | |
var regChar =/[A-Za-z]/; | |
var regSymbol =/[^A-Za-z0-9]/; | |
if(regNum.test(val) ) { i++; } | |
if(regChar.test(val) ) { i++; } | |
if(regSymbol.test(val)) { i++; } | |
if (l < 6 || l > 16){ result = -1; } | |
else if(l <= 8 && i == 1) { result = 1 ; } | |
else if(l > 8 && i == 1) { result = 2 ; } | |
else if(l <= 8 && i == 2) { result = 2 ; } | |
else if(l > 8 && i == 2) { result = 3 ; } | |
else if(i == 3) { result = 3 ; } | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment