Answers for "jquery validation engine example for file upload allowed extension"

0

jquery validation engine example for file upload allowed extension

<script>
  ;(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!' );
        }
      }
    });
  })(jQuery);
</script>
Posted by: Guest on August-13-2021

Code answers related to "jquery validation engine example for file upload allowed extension"

Code answers related to "Javascript"

Browse Popular Code Answers by Language