Skip to content

Instantly share code, notes, and snippets.

@niczak
Last active April 12, 2021 08:22
Show Gist options
  • Save niczak/5470218 to your computer and use it in GitHub Desktop.
Save niczak/5470218 to your computer and use it in GitHub Desktop.
Check file extension w/ JavaScript
function checkFile(file) {
var extension = file.substr((file.lastIndexOf('.') +1));
if (!/(pdf|zip|doc)$/ig.test(extension)) {
alert("Invalid file type: "+extension+". Please use DOC, PDF or Zip.");
$("#file").val("");
}
}
@mmhashemi
Copy link

mmhashemi commented Apr 12, 2021

thank you, but, I can set dynamic extension in this function? because you used regular expressions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment