密碼校驗

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)

}

})
複製代碼
相關文章
相關標籤/搜索