Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery validation for confirm password [duplicate]

I am using Jquery for form validation , in that I have password and confirm password fields like this,

<input type="password" class="form-control" name="password" id="password">
<input type="password" class="form-control" name="cfmPassword" id="cfmPassword" >

Here other fields are working fine but not confirm password field, The rule for cfmPassword is as follow ,

password: {
    required: true,
    minlength: 6,
    maxlength: 10

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

but here the problem is if cfmpassword is not same as password also it doesnt show error message. please any one help me in this.

like image 797
user3599482 Avatar asked Jun 10 '14 11:06

user3599482


1 Answers

working fiddle here

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

               }
     }

});
like image 170
faby Avatar answered Oct 06 '22 04:10

faby