// Accept a value from a file input based on a required mimetype$.validator.addMethod("accept",function(value,element,param){// Split mime on commas in case we have multiple types we can acceptvartypeParam=typeofparam==="string"?param.replace(/\s/g,"").replace(/,/g,"|"):"image/*",optionalValue=this.optional(element),i,file;// Element is optionalif(optionalValue){returnoptionalValue;}if($(element).attr("type")==="file"){// If we are using a wildcard, make it regex friendlytypeParam=typeParam.replace(/\*/g,".*");// Check if the element has a FileList before checking each fileif(element.files&&element.files.length){for(i=0;i<element.files.length;i++){file=element.files[i];// Grab the mimetype from the loaded file, verify it matchesif(!file.type.match(newRegExp(".?("+typeParam+")$","i"))){returnfalse;}}}}// Either return true because we've validated each file, or because the// browser does not support element.files and the FileList featurereturntrue;},$.validator.format("Please enter a value with a valid mimetype."));