Nitul
Nitul

Reputation: 1035

HTML5 - Restrict file upload

<input type="file" accept=".csv" /> 

Above code allows to uploading of .txt or any type of file also.

How to restrict other file types in html5?

Upvotes: 2

Views: 3152

Answers (3)

Nitul
Nitul

Reputation: 1035

You can't restrict other file types in html5 file input, if user select other files it allow to select. Attribute 'accept' just give hint to user about supported file types.

Upvotes: 2

dyaa
dyaa

Reputation: 1450

Try this

<input id="fileSelect" type="file" accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" />

Also Check this with more details http://jsfiddle.net/dirtyd77/LzLcZ/144/

Upvotes: 0

angussidney
angussidney

Reputation: 686

With the input attribute you can specify any file extension to be uploaded. To add multiple attributes, separate them with a comma as so:

<input type="file" accept=".txt,.jpg">

You can also set a predefined family of extensions to be available for upload. Simply use either audio/*, video/*, or image/* to select those file types respectively. These can also be combined with regular file extensions. E.g.

<input type="file" accept="image/*,.psd">

This lets you upload an image or Photoshop file.

I hope this helps!

Upvotes: 1

Related Questions