密码校验

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)

}

})
复制代码

转载于:https://juejin.im/post/5cede719f265da1bb31c1aa6

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值