Closed
Description
This is a mix between jquery-validation and Modernizr, although we can port the Modernizr part out so Modernizr is not a dependency.
I'm wondering if you are open to having me add it to additional-plugins? It is a great feature :)
// Validate file input on change
jQuery.validator.addMethod("filesize", function(value, element, param) {
// This requires Modernizr filereader community add-on:
// <https://github.com/Modernizr/Modernizr/blob/master/feature-detects/file-api.js>
var valid = true;
if (Modernizr.filereader) {
// Check if file size is valid
// (e.g. value = "10485760" = 10mb)
for(var i=0;i<element.files.length;i+=1) {
if (element.files[i].size > param) valid = false;
}
}
return this.optional(element) || valid;
}, "File exceeds maximum upload size.");