6

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.

Sparky
  • 98,165
  • 25
  • 199
  • 285
user3599482
  • 157
  • 2
  • 3
  • 15
  • You have not shown enough code to reproduce the issue. I make this claim because the accepted answer below contains the same code as your OP. – Sparky Jun 11 '14 at 21:48

2 Answers2

14

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"

               }
     }

});
faby
  • 7,394
  • 3
  • 27
  • 44
  • Your code is the same as the OP's so I guess I don't understand the original problem. – Sparky Jun 11 '14 at 21:45
  • There was some sintax error.. Maybe the question has been updated – faby Jun 11 '14 at 21:49
  • BTW, you only need the `equalTo` rule on the second field: http://jsfiddle.net/BSdc8/3/ – Sparky Jun 11 '14 at 21:49
  • I'm not faulting your answer... I'm just trying to find out what we're solving here. Your answer merely proves the OP's code should have been working all along. – Sparky Jun 11 '14 at 21:50
  • The user was searching for a working example of his code I thought.... So I decided to write a complete fiddle with his code and not only mark the syntax errors. If you want I provide a better explanation – faby Jun 11 '14 at 21:56
  • 1
    Like I said, I don't see anything wrong with your answer. I just think the OP should have shown more code or explained where he went wrong. – Sparky Jun 11 '14 at 22:05
0

There was syntax error

just added colon in password: after maxlength: 10,

your code working fine.now

<script>

  $("#Myform").validate({
   rules: {
     password: { 
       required: true,
       minlength: 6,
       maxlength: 10,

     } , 

     cfmPassword: { 

      equalTo: "#password",
      minlength: 6,
      maxlength: 10
    }


  }

});
</script>
VishAl
  • 388
  • 3
  • 17
Mr7-itsurdeveloper
  • 1,631
  • 2
  • 17
  • 24