Created
October 31, 2014 12:16
-
-
Save shankardevy/c00a88468b2027185ac8 to your computer and use it in GitHub Desktop.
Restrict file upload by extension on html input tags
This file contains 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
// 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