I am using jquery for form validation. Rest is well except the confirm password field. Even when the same password is typed, the Please enter the same password. is not removed.
My script is:
<script type="text/javascript"> $(document).ready(function() { $("#form1").validate({ rules: { password: { required: true, minlength: 5 }, c_password: { required: true, equalTo: "#password", minlength: 5 }, email: { required: true, email: true }, phone: { required: true, number: true, minlength: 7 }, url: { url: true }, description: { required: true }, gender: { required: true } }, messages: { description: "Please enter a short description.", gender: "Please select your gender." } }); }); --> </script>
And inside the form tag:
<div class="form-row"><span class="label">Password</span><input type="password" name="password" class="required" id="password" /></div> <div class="form-row"><span class="label">Confirm Password</span><input type="password" name="c_password" id="c_password" /></div>
Any suggestion? Would be much thankful for the help.
jQuery('. validatedForm'). validate({ rules: { password: { required: true, minlength: 5 }, password_confirm: { required: true, minlength: 5, equalTo: "#password" } } });
To check confirm password field in form without reloading page with JavaScript, we can check the input values. to add the password inputs. const check = () => { if ( document. getElementById("password").
Steps to use express-validator to implement the logic:Install express-validator middleware. Create a validator. js file to code all the validation logic. Validate confirmPassword by validateConfirmPassword: check('confirmPassword') and chain on all the validation with ' .
The confirm password catches typos by prompting users to type their password twice. While the confirm password field seems sensible, including it can lower your conversion rate.
Your fields doesn't have the ID property. In jQuery the "#password" selector means "the object that has an id
property with value 'password'
"
Your code should look like this:
<input type="password" name="password" id="password" class="required"/>
<input type="password" id="password" class="nomal required error" value="" name="cpassword"> <input type="password" equalto="#password" class="nomal required error" value="" name="cpassword">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With