May 1, 2019
8
Level 13
How to file upload with restriction ?
i was try to upload file but when i click upload button to select custom file or all files now how to restrict all file option when i click upload button and only show in dialog box and choose specfic file when i was validate
please suggest thank you
Level 13
i did this using javascript
var _validFileExtensions = [".jpg", ".jpeg", ".docx", ".xlsx", ".pdf"];
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;
}
Please or to participate in this conversation.