Jquery Validate name=“name[]” not working

随声附和 提交于 2019-12-20 06:25:43

问题


I'm using the Validation plugin from bassistance.de I want to validate the folowing:

<form class="cmxform" id="form1" action="ufm/mailit.php" method="post">
<fieldset>
<input type="checkbox" value="namea" name="name[]" id="namea" /> <label for="namea">Name a</label>
<input type="checkbox" value="nameb" name="name[]" id="nameb" /> <label for="nameb">Name b</label>
<input type="checkbox" value="namec" name="name[]" id="namec" /> <label for="namec">Name c</label>
<button type="submit" id="RegisterButton" name="ButtonValue" value="Aanvragen">Submit</button>
</fieldset>
</form>

And using this javascript:

$(document).ready(function() {
        $("#form1").validate({
            rules: {

                vraag2[]: {required: true, minlength: 1}
                         },

            messages: {
                vraag2[]: "Make at least one choice"
            }
        });
});

But it's not working, It has to do with the [] characters how can I use those characters with the validation plugin?

Thanks!
Edski


回答1:


Names in JavaScript object literals must be quoted if they contain non-alphanumerics (or are keywords):

"vraag2[]": "Make at least one choice"


来源:https://stackoverflow.com/questions/3708097/jquery-validate-name-name-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!