我有很多形式为
我有这个 HTML
<form method="post" id="form_commento-[i]" class="form_fancybox_commenti">
<div class="form-section">
<span style="position: relative">
<input type="text" id="commento_form_[i]_commento" name="commento_form_[i][commento]" required="required"/>
<button type="submit" class="submit-button" id="submit_form_commenti">Commenta</button>
</span>
</div>
</form>
其中 [i] 是索引
在我准备好的文件中,我有
$(document).ready(function() {
jQuery.validator.addMethod("alphanumeric", function (value, element) {
return this.optional(element) || /^[a-zA-Z0-9\n\-'àèìòù: <_,. !?()]*$/.test(value);
}, "error");
$('.form_fancybox_commenti').each(function(index, numero_form) {
var theRules = {};
theRules[
'commento_form_['+index+'][commento]'] = {alphanumeric: true};
$(this).validate({
rules: theRules,
submitHandler: function(form) {
save(form);
}
});
});
但我的自定义规则不起作用。
无论如何要解决这个问题?