使用jquery规则确认密码不起作用

时间:2018-09-20 08:46:31

标签: jquery codeigniter jquery-validate password-confirmation

我需要在cpassword中获得相同的密码。但是在这里,尽管密码匹配,但会给出密码不匹配的错误。当我删除equalTo规则时,这些方法就可以正常工作。

所以我认为问题出在'cpassword'

rules: {
    password: {
      required: true,
      minlength: 8,
      remote: {
        url: baseURL + "member/checkPassword1",
        type: "post",
        data: {
          action: function() {
            return "checkPassword1";
          }
        }
      }
    },
    cpassword: {
      required: true,
      equalTo: "#password"
    }
  },
  messages: {
    password: {
      required: "Please enter the password!",
      minlength: "Password should contain at least 8 character!"
    },
    cpassword: {
      required: "Please confirm the password!",
      equalTo: "Confirm password doesn't match the Password"
    }
  },

视图

<div class="form-group">
    <label class="headlabel"><?=$this->lang->line("Password");?><strong>*</strong></label>
    <input class="formtext form-control" type="password" name="password" id="password" value="<?php echo set_value('password'); ?>" onkeypress="removeerror('password')" placeholder=" <?=$this->lang->line("Enter_your_passwrd");?> ">
    <span class="glyphicon glyphicon-remove right errorcross" id="password_cross" style=""></span>
    <label class="errorlabel" id="password_error"><?php echo form_error('password'); ?></label>
</div>
<div class="form-group">
    <label class="headlabel"><?=$this->lang->line("Confirm_password");?><strong>*</strong></label>
    <input class="formtext form-control" type="password" name="cpassword" id="cpassword1" value="<?php echo set_value('cpassword'); ?>" onkeypress="removeerror('cpassword')" placeholder=" <?=$this->lang->line("Retype_your_passsword");?> ">
    <span class="glyphicon glyphicon-remove right errorcross" id="cpassword_cross" style=""></span>
    <label class="errorlabel" id="cpassword_error"><?php echo form_error('cpassword'); ?></label>
</div>

有人对此有任何想法吗?我该如何纠正?

1 个答案:

答案 0 :(得分:0)

在用于cpassword输入元素的HTML中添加data-rule-equalto='#password'属性并进行检查