Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 877263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:34:40+00:00 2026-05-15T11:34:40+00:00

I am trying to find out how to allow users to only select certain

  • 0

I am trying to find out how to allow users to only select certain files when the file browse window opens when an input of type file is clicked. I couldn’t come up with a solution for this. Any ideas? I thought the accept attribute would work but I didn’t get much luck with that, is the below implemented correctly?

<input id="file_zip" type="file" name="file_zip" accept="zip" />

Failing with the above, I have come up with a work around of getting the file name on change so I can do checks on it but this event fires only when something changes. A user can easily select the same file and continue without firing that event again! What event can I use instead?

Any help would be great!

    $('#file_zip').change(function() {

            alert($('#file_zip').val());

    });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T11:34:41+00:00Added an answer on May 15, 2026 at 11:34 am

    you can check the file extension before the submit, here is some example code

       $("#DocumentUploadForm").submit(function(data) {
    
            //File-Extension Check - does _NOT_ replace a server-side validation
            var filename = $("#FileToUpload").val()
            if (filename.length == 0) { return false };
    
            var dot = filename.lastIndexOf(".");
            if (dot == -1) { return false };
    
    
            var extension = filename.substr(dot, filename.length).toLowerCase();
            var extensionWhitelist = new Array(".doc", ".docx", ".xls", ".xlsx",
                                                ".pdf", ".odt", ".jpg", ".gif", ".png",
                                                ".tif", ".tiff", ".jpeg");
    
            if ($.inArray(extension, extensionWhitelist) == -1) {
                alert("The file extension " + extension + " is not allowed.");
                return false
            };
    
    
        });
    

    but you still need to preform a server-side check, this is also the only place were you can check the acutual type of the file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find out how to allow only .ac.uk emails register to
I'm currently trying to find out if there is a way to allow our
I'm trying to figure out how to allow users to click on a Google+
Trying to find out if it's possible to use SQLAlchemy on Heroku. Thanks.
I trying to find out the visibility of the Excel and do some activities
I am trying to find out how to write an SQL statement that will
i m trying to find out how to convert timestamp date and time (
I am trying to find out a way to set a time tag to
I am trying to find out if an instance of an application (not vb.net)
I'm trying to find out how to change the icon of a JStree node

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.