Created
May 5, 2014 18:50
-
-
Save h2rd/575a954540443cb46271 to your computer and use it in GitHub Desktop.
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
| <script type="text/javascript"> | |
| $(function(){ | |
| $('input#submit').click(function(){ | |
| var file = $('input[type="file"]').val(); | |
| var exts = ['doc','docx','rtf','odt']; | |
| // first check if file field has any value | |
| if ( file ) { | |
| // split file name at dot | |
| var get_ext = file.split('.'); | |
| // reverse name to check extension | |
| get_ext = get_ext.reverse(); | |
| // check file type is valid as given in 'exts' array | |
| if ( $.inArray ( get_ext[0].toLowerCase(), exts ) > -1 ){ | |
| alert( 'Allowed extension!' ); | |
| } else { | |
| alert( 'Invalid file!' ); | |
| } | |
| } | |
| }); | |
| }); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment