使用jquery验证插件确认对字段组的验证

时间:2014-12-30 10:19:33

标签: jquery jquery-validate

我有一个地址字段街道,城市,州,邮政编码的表格,我有另一个组与确认地址相同的字段。我想在jQuery validation plugin中的地址和确认地址之间应用 equalTo 插件选项。还要查找此确认案例的组错误消息,如下所示。

表格模式

Address

   street
   city
   state
   zipcode


Confirm Address

   street                    > error : Your address is not matching 
   city
   state
   zipcode

1 个答案:

答案 0 :(得分:2)

this

怎么样?
$(function () {
    $("#addressForm").validate({
        group:{
            address : "street city state zipcode",
            confirm_address : "street1 city1 state1 zipcode1",
        },
        rules: {
            street: {
                required: true
            },
            city: {
                required: true
            },
            state: {
                required: true
            },
            zipcode: {
                required: true
            },
            street1: {
                required: true,
                equalTo : "#street"
            },
            city1: {
                required: true,
                equalTo : "#city"
            },
            state1: {
                required: true,
                equalTo : "#state"
            },
            zipcode1: {
                required: true,
                equalTo : "#zipcode"
            }
        }
    });
});