Skip to content

Instantly share code, notes, and snippets.

@dkesberg
Created November 15, 2013 08:32
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dkesberg/7481028 to your computer and use it in GitHub Desktop.
Save dkesberg/7481028 to your computer and use it in GitHub Desktop.
jQuery Validator method for maximum filesize
jQuery.validator.addMethod("filesize_max", function(value, element, param) {
var isOptional = this.optional(element),
file;
if(isOptional) {
return isOptional;
}
if ($(element).attr("type") === "file") {
if (element.files && element.files.length) {
file = element.files[0];
return ( file.size && file.size <= param );
}
}
return false;
}, "File size is too large.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment