我想使用jQuery-Validation-Engine来验证文件输入的MIME类型.我怎么能这样做? 我的方法是这样的: function checkMIME(field, rules, i, options){ var file = $("#userfile")[0].files[0]; var MimeFilter = /^(image\/bmp|
我的方法是这样的:
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; } }
感谢名单
Kashuda
"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." },