密码和确认密码验证

html:

<tr>
    <td align="right">密码&nbsp;</td>
    <td><input type="text" id="password" name="password" class="salesInfo" onkeyup="value=value.replace(/[^\d]/g,'')" maxlength=6/></td>
</tr>
<tr>
    <td align="right">确认密码&nbsp;</td>
    <td><input type="text" id="confirmPassword" name="confirmPassword" class="salesInfo" onkeyup="value=value.replace(/[^\d]/g,'')" maxlength=6/></td>
</tr>

js:

$('#confirmPassword').keyup(checkPasswords);
		
		// 判断两次输入的密码是否一致
		function checkPasswords() {
	        var password = $("#password").val();
	        var confirmPassword = $("#confirmPassword").val();
	        
			if(!confirmPassword || confirmPassword.length < password.length){
				return;
			}
	 
	        if (password != confirmPassword){
	            alert("两次输入的密码不匹配");
	            document.getElementById("confirmPassword").focus();
	            return;
	        }
	    }



你可能感兴趣的:(密码和确认密码验证)