2012-03-19 228 views
0

如何去验证基于一个有效的电子邮件地址已经提供了密码?jQuery验证依赖

这里是我的设置:

$("#login-form").validate({ 
    rules: { 
     email: { 
      required:true, 
      email:true, 
      remote:"check_email.php" 
     }, 
     password: { 
      required:true, 
     } 
    }, 
    messages: { 
     email: { 
      required:"Please enter an email address.", 
      email:"Invalid email.", 
      remote:"Incorrect email." 
     }, 
     password: { 
      required:"Please enter a password.", 
     } 
    } 
}); 

我可以通过它传递给PHP脚本足以验证一个电子邮件地址,方便,查询数据库,但我怎么能保证即使电子邮件是有效的,相应的密码可能不会?

这里任何帮助将不胜感激!谢谢。

+0

你可能要检查他们两个表单提交的服务器上,而不是客户端验证。 – Rup 2012-03-19 02:06:39

回答

0

我会做的是,使用当前规则运行de验证,而使用提交按钮我将使用常规按钮<button type="button" onClick="submitFunction()">Submit</button>,如果全部有效然后验证密码,我不知道是什么究竟是什么你试图验证,但继承人一个小例子:

function submitFunction(){ 
    var $form = $('form'); 
    $form.validate({(here goes all your rules)}); 
    if (!$form.valid){ 
    return; 
    } 
    // here you can do your password validation or other validations on the client side 
    $.ajax({ 
    uri: 'myServerSideValidatorOrSubmitUrl.php', 
    type: 'POST' 
    data: $form.serializeArray(), 
    success: function(data) { 
     // if this ajax is for server side validation then submit the form,  
     $form.submit(); 
     // otherwise show form response 
     alert('all OK'); 
    } 
    }) 
} 

我还没有测试此代码,但是这是基本的想法。