jQuery验证插件.两个自定义规则不起作用
我正在使用jQuery验证引擎,并且有两个自定义规则需要在一个字段中使用.我已经一一尝试了它们,它们都工作正常.如何同时附加两者?
I'm using jQuery validation engine and I have two custom rules that I need to use for one field. I've tried both of them one by one, they work fine. How do I attach both?
class="validate[required,custom[OFS, onlyLattinLetters], maxSize[140]]"
或
class="validate[required,custom[OFS], custom[onlyLattinLetters], maxSize[140]]"
不起作用.
您是否尝试过在插件初始化函数中声明它们而不是内联类?
Instead of inline classes, have you tried declaring them within the plugin initialization function?
$(document).ready(function() {
$('#myForm').validate({
rules: {
myField: {
required: true,
OFS: true,
onlyLattinLetters: true,
maxSize: 140
}
}
});
});
编辑:
我建议您完全避免使用内联代码;我认为维护起来更加困难,使HTML变得冗长,并且将功能与演示样式混合在一起.
I would recommend totally avoiding inline code; I think it's more difficult to maintain, makes your HTML verbose, and it mingles functionality with your presentation styles.
我还删除了下面的示例(查看编辑历史),该示例是在jQuery讨论论坛中找到的,因为我找不到有关正确语法和用法的任何正式文档.
I also removed my example below (see edit history), which I found in the jQuery discussion forum, since I cannot find any official documentation on proper syntax and usage.