user3599482 user3599482 - 5 months ago 27
jQuery Question

Jquery validation for confirm password

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.

Answer

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"

               }
     }

});
Comments