Created
November 15, 2013 08:32
-
-
Save dkesberg/7481028 to your computer and use it in GitHub Desktop.
jQuery Validator method for maximum filesize
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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