Skip to content

Instantly share code, notes, and snippets.

@shankardevy
Created October 31, 2014 12:16
Show Gist options
  • Save shankardevy/c00a88468b2027185ac8 to your computer and use it in GitHub Desktop.
Save shankardevy/c00a88468b2027185ac8 to your computer and use it in GitHub Desktop.
Restrict file upload by extension on html input tags
// HTML
// <input type="file" data-allowed-files="pdf|jpeg"/>
$('#file').on('change', function(e){
var types = new RegExp('(\\.)('+ $(e.target).data('allowed-files') + ')$', 'i');
if(!types.test(this.value)
alert('not allowed');
this.value='';
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment