Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery confirm password validation

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.

like image 554
Aryan G Avatar asked Nov 03 '10 07:11

Aryan G


People also ask

How can I get new password and confirm password using jQuery?

jQuery('. validatedForm'). validate({ rules: { password: { required: true, minlength: 5 }, password_confirm: { required: true, minlength: 5, equalTo: "#password" } } });

How do I confirm a password field in form without a reloading page?

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").

How do I compare password and confirm password in node JS?

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 ' .

What is the Confirm password?

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.


2 Answers

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"/> 
like image 57
MatuDuke Avatar answered Sep 22 '22 21:09

MatuDuke


<input type="password" id="password" class="nomal required error" value="" name="cpassword">  <input type="password" equalto="#password" class="nomal required error" value="" name="cpassword"> 
like image 39
Thiwanka Avatar answered Sep 20 '22 21:09

Thiwanka