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 6575495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:23:37+00:00 2026-05-25T15:23:37+00:00

Today I faced an interesting thing as FF File API and separate files by

  • 0

Today I faced an interesting thing as FF File API and separate files by their types. OK here is a little snippet as

if (!input.files[0].type.match('image.*')) {
            window.alert("Select image please");
            return;
        }

it controls image being read only. But what about doc files and pdf for example? I couldn’t find useful examples for this thing so I hope you can share some snippets. The thing I am interested in detecting different file types but how can I control different file types with JS and its type.match bound?

Here is the base code

Any useful comment is appreciated 🙂

  • 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-25T15:23:38+00:00Added an answer on May 25, 2026 at 3:23 pm

    So the base idea is that this code uses File Objects, for more info on them see :

    • http://www.w3.org/TR/FileAPI/ (the spec)
    • https://developer.mozilla.org/en/DOM/File (Mozilla implementation)
    • https://developer.mozilla.org/en/DOM/FileReader

    As specified per w3, the type attribute of the File object is a MIME type. This is defined in the RFC 2046. But the spec itself isn’t the most interesting part, what’s more interesting is the list of the existing MIME type here or the most used one here.

    In this code, they use the type attribute and execute a regexp on it (see match and RegExp for more info). Their regexp says that it’s ok if the type contains image.

    To make your own selector, you’ll have to combine the above. (some of the example use === instead of match because the mime type is the entire type)
    For example the following check are possible:

    • document (not pdf only, odt have this type as well for example) : input.files[0].type==='application/pdf'
    • audio : input.files[0].type.match('audio.*')
    • video : input.files[0].type.match('video.*')

    And so on.

    After that you can use a selector on the name attribute of the file if you wish to match only certain extension (for example to check between different kind of document, you could look if it’s a .pdf, a .odt …) using for example input.files[0].name.match('\.pdf').
    But imho that’s not advised, as the user could easily play with that (removing or changing them).

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

Sidebar

Related Questions

Today I faced an interesting issue. I've been having an inheritance hierarchy with Hibernate
I was faced today with the following DUs declarations: type Grammar = Definition list
Today we faced a quite simple problem that were made even simpler by the
Today I faced a strange problem in C#. I have an ASP.NET page where
Today when I was in computer organization class, teacher talked about something interesting to
Today I faced a strange problem. I have an application which is the same
Today I faced one question in interview. Is it possible to apply inheritance concept
Today I faced the following problem: I registered a new user on my Joobla
Today I faced an error due to which my Android application is getting by
Today I faced a problem that there is one memory leak in my iphone

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.