Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery validate if input not empty

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.

like image 277
T_E_M_A Avatar asked May 27 '26 06:05

T_E_M_A


1 Answers

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.

like image 164
brianlmerritt Avatar answered May 30 '26 06:05

brianlmerritt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!