jQuery Confirm Password Validation

jQuery Confirm Password Validation

tudip-logo

Tudip

24 June 2016


OK, so you have created that fancy registration form and now you want to add a validation where password and confirm password fields match. You add the JQuery validate JS and then you realize that there is no inbuilt function for confirm password in the JQuery validate framework 🙂

Follow the steps mentioned below and you can get this working.

$.validator.addMethod('c_password', function(value){
    if(value == $('#password').val()){
        return true;
     }
     return false;
}, "Password and confirm password fields do not match");
And give ‘c_password’ class to the confirm password field and change the validation message as per your requirements.
Now few people might think, it is overkill and it can be done with Rules. But as in long run, you would have to learn to add your own validations anyway, why not start with the simplest thing? 🙂
If you face problems, do drop us a line and we can help you out.
Happy Coding!!

search
Request a quote