Last active
April 12, 2021 08:22
-
-
Save niczak/5470218 to your computer and use it in GitHub Desktop.
Check file extension w/ JavaScript
This file contains hidden or 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
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(""); | |
} | |
} |
:) nice thanks
thankyou :> ♥
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
very good, thank you for your code