1. 程式人生 > >密碼正則驗證

密碼正則驗證

.html 匹配 htm != 判斷 密碼 ret 是否 -1

/**密碼、驗證碼非空輸入的判斷*/
function checkCode() {
password = $.trim($("#password").val());
rpw = $.trim($("#rpw").val());
var reg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,12}$/;
alert("密碼框的值:"+ password);
alert("判斷密碼是否匹配:"+ reg.test(password))
if (!password || !reg.test(password)) {
$("#password").next().html("請輸入6-12位數字、字母組合的密碼!");
return false;
}else if(rpw == "" || rpw != password){
$("#rpw").next().html("兩次密碼不一致,請重新輸入!");
return false;
}else{
$("#password").next().html("");
$("#rpw").next().html("");
return true;
}
}

密碼正則驗證