开发者

Trying to validate an array of textfields using jQuery

I am trying to validate the following form using jQuery plugin but not successful yet. Please help me with the issue.

<ol>
        <li>
            <label for="address1" class="biz">Address 1<span class="required">*</span></label>
            <input id="address1" name="address[address1]" class="text" type="text" >
        </li>
        <li>
            <label for="address2" class="biz">Address 2</label>
            <input id="address2" name="address[address2]" class="text开发者_JAVA技巧" type="text"/>
        </li>
        <li>
            <label for="city" class="biz">City<span class="required">*</span></label>
            <input id="city" name="address[city]" class="text" type="text"/>
        </li>

goes on....

rules: {
        name: { required: true },
        phone: { required: true },
        address: { required: true },                                                                        
}

The above rule is not working. Thank you guys in advance.


You need to use the full field names and quote them. REF: http://docs.jquery.com/Plugins/Validation/Reference#Fields_with_complex_names_.28brackets.2C_dots.29

$("#form").validate({
    rules: {
        "address[address1]": { required: true },
        "address[address2]": { required: true },
        "address[city]": { required: true },
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜