Skip to content

Instantly share code, notes, and snippets.


Alice acmartinsal

View GitHub Profile
acmartinsal / gist:03252d11eb03a9448c4d
Last active Dec 3, 2015
Validator for input type file in Parsley 2.x
View gist:03252d11eb03a9448c4d
.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;