jquery validation engine example for file upload allowed extension

Solutions on MaxInterview for jquery validation engine example for file upload allowed extension by the best coders in the world

showing results for - "jquery validation engine example for file upload allowed extension"
Roberta
04 Mar 2016
1<script>
2  ;(function($) {
3    $('input#submit').click(function() {
4      var file = $('input[type="file"]').val();
5      var exts = ['doc','docx','rtf','odt'];
6      // first check if file field has any value
7      if ( file ) {
8        // split file name at dot
9        var get_ext = file.split('.');
10        // reverse name to check extension
11        get_ext = get_ext.reverse();
12        // check file type is valid as given in 'exts' array
13        if ( $.inArray ( get_ext[0].toLowerCase(), exts ) > -1 ){
14          alert( 'Allowed extension!' );
15        } else {
16          alert( 'Invalid file!' );
17        }
18      }
19    });
20  })(jQuery);
21</script>