Jquery密码强度校验

function passValidate(){
var password=$password.val().trim()
if(password===""){
$mima.addClass('has-error')
$password.after('<lable class="help-block">密码不能为空</lable>')
return false
}
//密码为八位及以上并且字母数字特殊字符三项都包括
var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\W).*$", "g");
//密码为七位及以上并且字母、数字、特殊字符三项中有两项,强度是中等
var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
var enoughRegex = new RegExp("(?=.{6,}).*", "g");
if (false == enoughRegex.test(password)) {
} else if (strongRegex.test(password)) {
$password.after('<lable class="help-block"><span class="qiang">密码强度强</span></lable>')
} else if (mediumRegex.test(password)) {
$password.after('<lable class="help-block" ><span class="zhong">密码强度中</span></lable>')
} else {
$password.after('<lable class="help-block" ><span class="ruo">密码强度弱</span></lable>')
}

return true
}
原文地址:https://www.cnblogs.com/cuiguangpeng/p/9944817.html