I need to allow select file dialog to accept any file type except some specific type, for example I need to make the dialog displays everything except for .exe files,
Asked
Active
Viewed 1,951 times
0
-
take a look at this http://stackoverflow.com/questions/3521122/html-input-type-file-apply-a-filter – yantaq Jul 11 '15 at 01:10
1 Answers
0
I see this question is already exist and have good answer. Please check the bellow link Validation of file extension before uploading file
var _validFileExtensions = [".jpg", ".jpeg", ".bmp", ".gif", ".png"];
function Validate(oForm) {
var arrInputs = oForm.getElementsByTagName("input");
for (var i = 0; i < arrInputs.length; i++) {
var oInput = arrInputs[i];
if (oInput.type == "file") {
var sFileName = oInput.value;
if (sFileName.length > 0) {
var blnValid = false;
for (var j = 0; j < _validFileExtensions.length; j++) {
var sCurExtension = _validFileExtensions[j];
if (sFileName.substr(sFileName.length - sCurExtension.length, sCurExtension.length).toLowerCase() == sCurExtension.toLowerCase()) {
blnValid = true;
break;
}
}
if (!blnValid) {
alert("Sorry, " + sFileName + " is invalid, allowed extensions are: " + _validFileExtensions.join(", "));
return false;
}
}
}
}
return true;
}
<form onsubmit="return Validate(this);">
File: <input type="file" name="my file" /><br />
<input type="submit" value="Submit" />
</form>

Community
- 1
- 1

Dinidu Hewage
- 2,169
- 6
- 40
- 51
-
Thanks, this will do the job, but what I need is not to show unsupported files at all in the dialog. – Baha' Al-Khateib Aug 07 '15 at 17:03