密码比较



我的代码有很大的问题。在注册中,我比较了我的PassOwrd,并且他显示密码不匹配。这是代码

{!! Form::open(array('url' => 'auth/postregister', 'class' => 'horizontal-form', 'id' => 'formRegister', 'method' => 'POST')) !!}
    {{ csrf_field() }}
                <label>Email</label>
                {!! Form::text('u_email', null, array('placeholder' => 'youremail@domaine.com', 'class' => 'form-group', 'id' => 'u_email', 'required')) !!}
                <label>Mot de passe</label>
                {!! Form::password('pwd1', null, array('placeholder' => '********', 'class' => 'form-group', 'id' => 'pwd1', 'required')) !!}
                <label>Confirmer votre mot de passe</label>
                {!! Form::password('pwd2', null, array('placeholder' => '********', 'class' => 'form-group', 'id' => 'pwd2', 'required')) !!}
                <p id="message"></p>
                <button type="submit" id="subscribe" class="btn btn-danger">S'enregistrer</button>
{!! Form::close() !!}
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/additional-methods.min.js"></script>
<script>
$("#formRegister").validate({
  rules: {
    pwd1: "required",
    pwd2: {
      equalTo: "#pwd1"
    }
  }
});
</script>

在密码中确认输入是红色的,并且发布数据不会通过。你有一个想法

您可以扩展jQuery验证器以添加您的规则:

<script>
    jQuery.validator.addMethod( 'passwordMatch', function(value, element) {
        // The two password inputs
        var password = $("#pwd1").val();
        var confirmPassword = $("#pwd2").val();
        // Check for equality with the password inputs
        if (password != confirmPassword ) {
            return false;
        } else {
            return true;
        }
    }, "Your Passwords Must Match");
    $("#formRegister").validate({
        rules: {
            pwd1: {
                required: true,
                minlength: 5
            },
            pwd2: {
                required: true,
                minlength: 5,
                passwordMatch: true // the added rule
            }
        },
        // If you want some custome messages :)
        messages: {
            pwd1: {
                required: "What is your password?",
                minlength: "Your password must contain more than 5 characters"
            },
            pwd2: {
                required: "You must confirm your password",
                minlength: "Your password must contain more than 5 characters",
                passwordMatch: "Your Passwords Must Match" // custom message for mismatched passwords
            }
        }
    });
</script>

ps:source

最新更新