3

Good day. Help set Validate plugin to update user profile. There are two input fields, "new password" and "repeat new password".

Need if they are both empty, it does not perform any checks. And if in the "Password" something entered, the password check for validity and equality of the second password.
I tried something like this, but this "if" does not work.

$.validator.setDefaults({ ignore: ":hidden:not(select)" });

        $('#contact-form').validate({

        rules: {         
         if(passord.lenght){
            password: {
            minlength: 6,
            maxlength: 25,
            required: true,
            loginRegex: true
          },
          password_repeat: {
            minlength: 6,
            maxlength: 25,
           required: true,
            loginRegex: true,
            equalTo: "#password"
          }}
        },
});

I was looking for the answer in similar topics, but not found.

1
  • 1
    I'm guessing this has been coded quite a number of times. Take a look at sites like this one: jqueryvalidation.org/files/demo/milk Commented Jan 9, 2015 at 8:55

2 Answers 2

3

I like the first answer, but personally would not include the

minlength: 6,
maxlength: 10

In the cfmPassword. Either the first password matches the criteria, or generates an error. If that doesn't generate an error, the second password just has to match it.

Sign up to request clarification or add additional context in comments.

Comments

2

Can you try this:

<form id="formCheckPassword">
    <input type="password" class="form-control" name="password" id="password"/>
    <input type="password" class="form-control" name="cfmPassword" id="cfmPassword" />
    <input type="submit" value="submit"/>
 </form>



 $("#formCheckPassword").validate({
           rules: {
               password: { 
                 required: true,
                    minlength: 6,
                    maxlength: 10,

               } , 

                   cfmPassword: { 
                    equalTo: "#password",
                     minlength: 6,
                     maxlength: 10
               }


           },
     messages:{
         password: { 
                 required:"the password is required"

               }
     }

});

1 Comment

Everything was easier than I thought. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.