jquery - Validate input to only accept one type of file extension -


does know how can validate file input accept .zip files parsley.js?

i have looked around can not see how this.

you can custom validator validates extension of provided file path , check if it's zip. (check this jsfiddle):

<form id="myform">     <input type="file" name="some-file" data-parsley-fileextension='zip' />     <input type="submit" /> </form>  <script> $(document).ready(function() {     window.parsleyvalidator         .addvalidator('fileextension', function (value, requirement) {             // value contains file path, can pop extension             var fileextension = value.split('.').pop();              return fileextension === requirement;         }, 32)         .addmessage('en', 'fileextension', 'the extension doesn\'t match required');      $("#myform").parsley(); }); </script> 

note set attribute data-parsley-fileextension='zip' on input in order know extension must provided. on custom validator (which named fileextension) have take extension file path , check if matches 1 want.

you can check this answer find ways extension file path in javascript.

if need validate multiple extensions, have tweak solution bit.


Comments