1

Can anyone solve this fiddle. it has two fields password and confirm password. Validation needs to be done such that both password entered should be the same.

$(document).ready(function ()
{
    $('#EditForm').validate({ 
        rules: {
            password: {
                required: true
            },
            cpassword: {
                required: true,
                equalTo: "#password"
            }
        }
    });
});

http://jsfiddle.net/kalai789/aCZgK/2/

Thanks in advance

Kalaiarasan Manimaran
  • 1,598
  • 1
  • 12
  • 18

3 Answers3

3

Firstly the external version of jQuery you had loaded was very old (1.5.2) it appears incompatible with the current version of validate, I updated the fiddle to use 1.6.4 as that was the lowest available on jsFiddle. Secondly, the rules and other settings for the validate plugin are keyed on the name attribute of the element, not the id, so they need to be added:

<input type="password" name="password" id="password"/>
<input type="password" name="cpassword" value="" id="cpassword"/>

Working fiddle

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
2

use keyup method

http://jsfiddle.net/dbwMY/

check the info source https://stackoverflow.com/a/9717796/1768043

Community
  • 1
  • 1
X-Pippes
  • 1,170
  • 7
  • 25
  • thanks but i have been encouraged to use rules only . can you please solve that fiddle which i shared which is not working – Kalaiarasan Manimaran Oct 16 '13 at 09:20
  • @kalai: You need to actively run the check, when your input element changes. This is why X-Pippes used the keyup-Eventhandler, which then calls the check routine. You can not just "define" your checks... You have to actually run them, too. – SDwarfs Oct 16 '13 at 09:22
  • PS: This behaviour might have changed in future revisions of jQuery, where the event handler (form-submit Event) is attached automatically. – SDwarfs Oct 16 '13 at 09:24
  • 1
    Validating on keypress seems like overkill. It will tell they user what they have typed is invalid before they have finished, which could lead to confusion. – Rory McCrossan Oct 16 '13 at 09:36
1

Found similar question

Demo

jQuery('.validatedForm').validate({
    rules : {
        password : {
            minlength : 5
        },
        password_confirm : {
            minlength : 5,
            equalTo : "#password"
        }
    }
});
Community
  • 1
  • 1
Dr. Rajesh Rolen
  • 14,029
  • 41
  • 106
  • 178