带有Mime的jQuery验证引擎

时间:2013-06-29 22:20:05

标签: jquery jquery-validation-engine

我有这个自定义规则与jje验证引擎:

        "validateMIME":  {
            "func": function(field, rules, i, options){
            var fileInput = field[0].files[0];
            var MimeFilter = new RegExp(rules[3],'i');
            if (fileInput) {
            return MimeFilter.test(fileInput.type);
            } else { return true;}
            },
            "alertText": "* Estensione non supportata"
            },

问题是,只有在需要该字段时,这才有效。但在我的情况下,该字段不是必需的,但如果填充,则需要检查Mime类型。 如何编辑此功能以使用非必填字段?它出什么问题了? 感谢

1 个答案:

答案 0 :(得分:0)

尝试这个,因为它对我有用

    class="validate[optional,custom[validateMIME[application/msword| application/vnd.openxmlformats-officedocument.wordprocessingml.document|application/vnd.ms-excel]]]"

如果您遇到任何问题,请告诉我。