2017-02-03 675 views
1

我想验证新密码并确认新密码。即使我输入了相同的密码也显示错误,例如两个密码必须相同。请帮我,我做错了。以下是我的html和jQuery代码。Jquery密码和确认密码验证不起作用正确

HTML表单

<form role="form" id="clientresetpassword" name="clientresetpassword" action="<?php echo site_url('Home/client_password_reset'); ?>" method="post" style="padding: 10px;"> 
    <div class="row"> 
    <?php echo validation_errors(); ?> 
    </div> 
    <div class="form-group"> 
    <label>Current Password <span class="mandatory"> *</span></label> 
    <input type="password" name="curpas" class="form-control" value="<?php echo set_value('curpas'); ?>" placeholder="Enetr Your Current password" required> 
    </div> 
    <div class="form-group"> 
    <label>New Password <span class="mandatory"> *</span></label> 
    <input type="text" name="newpass" class="form-control" placeholder="Enter Your New Password" value="" required> 
    </div> 
    <div class="form-group"> 
    <label>Confirm New Password <span class="mandatory"> *</span></label> 
    <input type="password" name="cnfnewpass" class="form-control" placeholder="Confirm New Password" value="" required> 
    </div> 
    <div class="form-group"> 
    <input type="password" class="btn btn-primary" name="reset_password" value="Reset Password"> 
    </div> 
</form> 

jQuery验证

(function($,W,D) 
{ 
    var JQUERY4U = {}; 

    JQUERY4U.UTIL = 
    { 
     setupFormValidation: function() 
     { 
      //form validation rules 
      $("#clientresetpassword").validate({ 
       rules: { 
         curpas: { 
          required: true, 
          minlength : 5, 
          maxlength : 15 
         }, 
         newpass:{ 
          required: true, 
          minlength: 5, 
          maxlength: 15 
         }, 
         cnfnewpass: { 
          required: true, 
          minlength: 5, 
          maxlength: 15, 
          equalTo: "#newpass" 
         }, 
        }, 
       messages: { 
         curpas: { 
          required: "Please enter Password", 
          minlength: "Password length must be min. of 5 characters long", 
          maxlength: "Password length must not Exceed 15 characters"   
         }, 
         newpass:{ 
          required: "Please enter New Password", 
          minlength: "New Password length must be min. of 5 characters long", 
          maxlength: "New Password length must not Exceed 15 characters" 
         }, 
         cnfnewpass: { 
          required: "Please enter Confirm New Password", 
          minlength: "Confirm New Password length must be min. of 5 characters long", 
          maxlength: "Confirm Password length must not Exceed 15 characters", 
          equalTo: "New Password and Confirm New Password must be same" 
         }, 
        }, 
       submitHandler: function(form) { 
        form.submit(); 
       } 
      }); 
     } 
    } 

    //when the dom has loaded setup form validation rules 
    $(D).ready(function($) { 
     JQUERY4U.UTIL.setupFormValidation(); 
    }); 

})(jQuery, window, document); 

回答

0

您必须设置ID为新密码字段 如

<input id="newpass" type="text" name="newpass" class="form-control" placeholder="Enter Your New Password" value="" required>

由于您使用jQuery验证一个ID选择即equalTo: "#newpass"

+0

谢谢你在@Manvir Singh工作 –

0

这里的问题是:

equalTo: "#newpass" // referring it by ID 

,但没有ID提供给:

<input type="text" name="newpass" class="form-control" placeholder="Enter Your New Password" value="" required> 

为其提供id属性。

+0

三江源它正在@Mayank Pandeyz –

+0

**三江源它工作**或感谢你的工作? –

+0

对不起@Mayank Pandeyz其工作..谢谢 –