jQuery Validation Engine with Mime

Posted by Diego Pucci on Stack Overflow See other posts from Stack Overflow or by Diego Pucci
Published on 2013-06-29T22:20:05Z Indexed on 2013/06/29 22:21 UTC
Read the original article Hit count: 286

I have this custom rule with tje jQuery validation Engine:

        "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"
            },

The problem is that this is working ONLY if the field is required. But in my case the field is not required, but if filled then the Mime type needs to be checked. How do I edit this function to work with non required fields? what's wrong with it? Thanks

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jquery-validation-engine