<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?
<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?
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.
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!
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/