Last active
December 16, 2015 20:29
-
-
Save whatgoodisaroad/5493025 to your computer and use it in GitHub Desktop.
Validity File Size Validation
This file contains 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
// This depends on a feature in modern browser as described in: | |
// http://stackoverflow.com/questions/3717793/javascript-file-upload-size-validation | |
// Add file uploads to validity's element support: | |
$.validity.settings.elementSupport += ", :file"; | |
// Create a validator for minimum file size (also requires the file): | |
// Using assert http://validity.thatscaptaintoyou.com/Demos/index.htm#Assert | |
$.fn.minFileSize = function(min) { | |
return this | |
.assert( | |
function(fup) { return !!fup.files.length; }, | |
"You should select a file" | |
) | |
.assert( | |
function(fup) { return fup.files[0].size >= min; }, | |
"The file is too small" | |
); | |
}; | |
// Now, in a validation session, can write... | |
var min = 10000; | |
$("#myFileUpload:file").minFileSize(min); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment