Password comparaison

Tojo RODIALSON

I have big problem with my code. In registration, I compare my passowrd and he display password don't match. This is code

{!! 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' => '[email protected]', '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>

In password confirm the input is red and post data don't pass. Have you an idea

Maraboc

You can extends the jQuery validator to add your rule like this :

<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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related