views:

73

answers:

1

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" 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.

+1  A: 

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 },
    }
});
BBonifield
that worked. Thanks BB for your help.