js校验密码,不能为空的8-20位非纯数字或字母的密码

 

jsp:

<div class="mui-input-row">

<label>密码</label><!-- id='password' -->
<input type="password" class="mui-input-clear mui-input" placeholder="请输入密码" name="password" onblur="return checkInput1();"style="
margin-top: 4px;
">
</div>
<span id="password_msg"style="color: #E41317;font-size: 12px"></span>
<div class="mui-input-row">
<label>确认</label>
<input type="password" class="mui-input-clear mui-input" placeholder="请确认密码" name = "checkpwd" onblur="return checkInput2();"style="
margin-top: 4px;
">
</div>

js:

function checkInput2(){

var pwdCheck = /^(?![\d]+$)(?![a-zA-Z]+$)(?![^\da-zA-Z]+$).{8,20}$/;
if ($("input[name=checkpwd]").val().length < 1) {
/* alert("请输入确认密码!"); */

document.getElementById("checkpwd_msg").innerText = "*确认密码不能为空";
return false;
}else if ($("input[name=checkpwd]").val().length < 8 ){
document.getElementById("checkpwd_msg").innerText = "*请输入8位以上的密码";
return false;
}else if(!pwdCheck.test($("input[name=checkpwd]").val())){
document.getElementById("checkpwd_msg").innerText = "*不能为纯数字或纯字母";
return false;
}else{
document.getElementById("checkpwd_msg").innerText = "";
}
if ($("input[name=checkpwd]").val() != $("input[name=password]").val()) {
/* alert("两次输入密码不一致!"); */
document.getElementById("checkpwd_msg").innerText = "*两次密码不一致";
return false;
}else{
document.getElementById("checkpwd_msg").innerText = "";
}
}

posted on 2018-09-27 16:53  贾广祥  阅读(2834)  评论(0编辑  收藏  举报

导航