使用jQuery Validate验证两个字段

前端之家收集整理的这篇文章主要介绍了使用jQuery Validate验证两个字段前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在使用jQuery Validate Plugin:
http://bassistance.de/jquery-plugins/jquery-plugin-validation/

简单演示:

  required email" />
  required email" />

如何检查两个输入中的值是否与jQuery或jQuery Validate Plugin相同.

我只是尝试了相同,它的工作原理:

rules: {
  email: 'required',email2: {equalTo: '.email'}
最佳答案
通过查看http://jquery.bassistance.de/validate/demo/的演示页面,您可以使用“equalTo”验证两个应该相等的字段:

    $("#signupForm").validate({
    rules: {
                    ...snip... 
        password: {
            required: true,minlength: 5
        },confirm_password: {
            required: true,minlength: 5,equalTo: "#password"
        },...snip...
    },messages: {
        ...snip...
        password: {
            required: "Please provide a password",minlength: "Your password must be at least 5 characters long"
        },confirm_password: {
            required: "Please provide a password",minlength: "Your password must be at least 5 characters long",equalTo: "Please enter the same password as above"
        },...snip...
    }
});

要使用类方法,只需要找到语法.我找不到equalTo属性,但它可能是这样的:

class="required email equalTo['email']"

猜你在找的jQuery相关文章