简体   繁体   中英

A Very Basic Confirm password validation not working

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

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

Found similar question

Demo

jQuery('.validatedForm').validate({
    rules : {
        password : {
            minlength : 5
        },
        password_confirm : {
            minlength : 5,
            equalTo : "#password"
        }
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM