我需要使用插件jQuery Validate验证textarea,为此我使用正则表达式并向插件添加一个方法:
$.validator.addMethod(
"regex",
function(value, element, regexp) {
var check = false;
var re = new RegExp(regexp);
return this.optional(element) || re.test(value);
},
"No special Characters allowed here. Use only upper and lowercase letters (A through Z; a through z), numbers and punctuation marks (. , : ; ? ' ' \" - = ~ ! @ # $ % ^ & * ( ) _ + / < > { } )"
);
Run Code Online (Sandbox Code Playgroud)
然后在选项中添加正则表达式:
comments:{
required: true,
maxlength: 8000,
regex: …Run Code Online (Sandbox Code Playgroud)