This Javascript can be used to allow only few file extension only.
Include Below Script
<script>
function validateFileExtension(fld)
{
if(!/(\.zip|\.rar|\.doc|\.docx|\.ppt|\.xls|\.xlsx|\.pptx|\.jpg|\.jpeg|\.pdf)$/i.test(fld.value))
{
alert("Invalid image file type.");
fld.value='';
fld.focus();
return false;
}
return true;
}
</script>
Call above function in HTML as given below:
<input type="file" name="uploadFile1" id="uploadFile1" onchange="return validateFileExtension(this)" />
Note:
Here as mention in Javascript only file with .zip, .rar, .doc, .docx, .ppt, .xls, .xlsx, .pptx, .jpg, .jpeg, .pdf will be allowed. This can be changed as per requirement.
No comments:
Post a Comment