Last active
December 3, 2015 16:09
-
-
Save acmartinsalmeida/03252d11eb03a9448c4d to your computer and use it in GitHub Desktop.
Validator for input type file in Parsley 2.x
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
window.Parsley | |
.addValidator('filemaxsize', { | |
requirementType: 'string', | |
validateString: function (val, req){ | |
var reqs = req.split('|'); | |
var input = $('input[type="file"][name="'+reqs[0]+'"]'); | |
console.log(reqs[0], reqs[1]); | |
var maxsize = reqs[1]; | |
var max_bytes = maxsize * 1000000, file = input.prop('files')[0]; | |
return file.size <= max_bytes; | |
}, | |
messages: { | |
en: 'The file is too big' | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment