Skip to content

Instantly share code, notes, and snippets.

@acmartinsalmeida
Last active December 3, 2015 16:09
Show Gist options
  • Save acmartinsalmeida/03252d11eb03a9448c4d to your computer and use it in GitHub Desktop.
Save acmartinsalmeida/03252d11eb03a9448c4d to your computer and use it in GitHub Desktop.
Validator for input type file in Parsley 2.x
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