Javascript 如何使用jQuery验证页面密码

Javascript 如何使用jQuery验证页面密码,javascript,jquery,asp.net-mvc-3,validation,Javascript,Jquery,Asp.net Mvc 3,Validation,我有一个div,它包含三个输入文本框(oldpassword、newpassword、confirmpassword) 旧密码* 新密码* 确认密码* 拯救 现在,我必须在jquery中验证以下场景中的页面: 1.旧密码不应为空。 2.新密码不应为空。 3.确认密码不应为空。 4.旧密码和确认密码应相同。 5.新密码长度应为8-16个字符,至少1个特殊字符,至少1个大写字母,至少1个数字值。这里有一个快速解决方案,我想这就是您想要的 function validatePassword(){

我有一个div,它包含三个输入文本框(oldpassword、newpassword、confirmpassword)


旧密码*
新密码*
确认密码*
拯救
现在,我必须在jquery中验证以下场景中的页面:

1.旧密码不应为空。 2.新密码不应为空。 3.确认密码不应为空。 4.旧密码和确认密码应相同。
5.新密码长度应为8-16个字符,至少1个特殊字符,至少1个大写字母,至少1个数字值。

这里有一个快速解决方案,我想这就是您想要的

function validatePassword(){
    var old_pass = $('#OldPassword').val();
    var new_pass = $('#NewPassword').val();
    var conf_pass = $('#ConfirmPassword').val();
    if(old_pass === ""){
        alert('Old password should not be blank.');
    }
    else if(new_pass === ""){
        alert('New password should not be blank.');
    }
    else if(conf_pass === ""){
        alert('Confirm password should not be blank');
    }
    else if(!new_pass.match(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*])[a-zA-Z0-9!@#$%^&*]{8,16}$/))
        alert('New password length should be 8-16 characters,atleast 1 special character,atleast 1 upper case,atleast 1 numericvalue');
    }
    else if(new_pass !== conf_pass){
        alert('New and confirm password should be same');
    }
    return false    
}
这应该可以做到。我穿上了

function validatePassword(){
    var old_pass = $('#OldPassword').val();
    var new_pass = $('#NewPassword').val();
    var conf_pass = $('#ConfirmPassword').val();
    if(old_pass === ""){
        alert('Old password should not be blank.');
    }
    else if(new_pass === ""){
        alert('New password should not be blank.');
    }
    else if(conf_pass === ""){
        alert('Confirm password should not be blank');
    }
    else if(!new_pass.match(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*])[a-zA-Z0-9!@#$%^&*]{8,16}$/))
        alert('New password length should be 8-16 characters,atleast 1 special character,atleast 1 upper case,atleast 1 numericvalue');
    }
    else if(new_pass !== conf_pass){
        alert('New and confirm password should be same');
    }
    return false    
}