小编Mar*_*rio的帖子

否认特殊字符jQuery Validate

我需要使用插件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)

regex jquery jquery-plugins jquery-validate

10
推荐指数
1
解决办法
3万
查看次数

标签 统计

jquery ×1

jquery-plugins ×1

jquery-validate ×1

regex ×1