密码校验

js实现密码校验

uPwd.addEventListener("blur", function () {

//var timer = null;

clearInterval(timer);

tips[1].style.display = "block";

var pwdVal = uPwd.value;

if (pwdVal.length < 6) {

tips[1].innerHTML = "密码长度必须是6-20,由字母、数字、下划线、特殊字符组成";

tips[1].style.color = "red";

timer = setTimeout(function () {

tips[1].style.display = "none";

},3000)

}

//密码验证规则,很实用

if (/^[a-zA-Z0-9_-]{6,20}$/.test(pwdVal)) {

//show.className = "success";

tips[1].innerHTML = "密码强度:弱";

tips[1].style.color = "gray";

timer = setTimeout(function () {

tips[1].style.display = "none"

}, 3000);

if (/^([a-z].*[A-Z])|([A-Z].*[a-z])$/.test(pwdVal)) {

tips[1].innerHTML = "密码强度:中等";

tips[1].style.color = "orange";

timer = setTimeout(function () {

tips[1].style.display = "none"

}, 3000)

}

if (/^([a-z].*[0-9])|([A-Z].*[0-9])|[0-9].*[a-zA-Z]$/.test(pwdVal)) {

tips[1].innerHTML = "密码强度:高";

tips[1].style.color = "hotpink";

timer = setTimeout(function () {

tip[1].style.display = "none"

}, 3000)

}

if (/^[A-Za-z0-9]+[_][A-Za-z0-9]*$/.test(pwdVal)) {

tips[1].innerHTML = "密码强度:很是高";

tips[1].style.color = "green";

timer = setTimeout(function () {

tips[1].style.display = "none"

}, 3000)

}

repwd = this.value;

} else {

tips[1].innerHTML = "密码不可用,必须是6-20位数字、字母、下划线、特殊字符";

tips[1].style.color = "red";

repwd = null;

timer = setTimeout(function () {

tips[1].style.display = "none"

}, 3000)

}

})
复制代码
相关文章
相关标签/搜索