I would like to use the jQuery-Validation-Engine to validate the MIME Type of a file input. How could I do this?
My approach would be something like this:
function checkMIME(field, rules, i, options){
var file = $("#userfile")[0].files[0];
var MimeFilter = /^(image\/bmp|image\/gif|image\/jpeg|image\/png|image\/tiff)$/i;
if (! MimeFilter.test(file.type)) {
return options.allrules.validate2fields.alertText;
}
}
Thanx Kashuda
OK, found a solution by adding these lines to the query.validationEngine-LANG.js
:
"validateMIME": {
"func": function(field, rules, i, options){
//add to input tag: data-validation-engine="validate[required, custom[validateMIME[image/jpeg|image/png]]]"
var fileInput = field[0].files[0];
var MimeFilter = new RegExp(rules[3],'i');
if (fileInput) {
return MimeFilter.test(fileInput.type);
} else { return true;}
},
"alertText": "* Wrong Mime Type."
},