我正在使用JQuery Validation插件http://jqueryvalidation.org/,我有以下情况:
示例HTML:
<input type="text" name="glass_name" id="glass_name">
<input type="text" name="glass_name_confirm" id="glass_name_confirm">
示例Javascript:
$("#form").validate({
rules: {
glass_name: {
required: true
},
glass_name_confirm: {
required: true,
equalTo: "#glass_name"
},
如何针对字符串字数组验证输入框内容?例如,我不希望文本框中的用户id = glass_name插入一个noapropiate单词列表:word1或word2或word3等。
提前致谢!
答案 0 :(得分:0)
制定自定义规则:
//添加新方法:
jQuery.validator.addMethod("validationFilterWords", function(value, element) {
var arrFilter = ["Word1","Word2"];
return this.optional(element) || ($.inArray(value,arrFilter) === -1);
}, "* Not allowed");
//添加新规则
rules : {
glass_name: {
validationFilterWords: true,
required: true
}
}