使用jQuery Validate确认密码 [英] Confirm Password with jQuery Validate

查看:552
本文介绍了使用jQuery Validate确认密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用jQuery validate插件来确认我的密码输入.

I'm trying to use jQuery validate plugin to confirm my password entry.

但是,我不希望它成为必填字段.

However, I don't want it to be a required field.

仅当用户想要更改密码时,他们需要进行确认.

Just IF a user wants to change the password, they would need to confirm it.

如果没有,则两个字段都不应验证.

If not, both fields shouldn't be validated.

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

这很正常,但是同样,两个字段都是必需的.

This is working perfectly, but again, both fields are required.

如果有人只想更改其电子邮件地址或用户名,并保留密码,我想选择此选项.

I would like to have this optional, in case someone just wants to change for instance their email or username and leave the password alone.

推荐答案

删除required: true规则.

演示:小提琴

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

这篇关于使用jQuery Validate确认密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆