Reputation: 565
I created an excel upload button in my HTML file.
<tr>
<td><label for="id_excel">Excel: </label></td>
<td class="fileUpload btn">
<input type="file" name="excel" id="id_excel" class="upload" />
</td>
</tr>
Since I created this button to get Excel files, I want to prevent users to upload something else (for example docx or pdf). How can I limit the user to upload only Excel file type?
Thanks.
Upvotes: 1
Views: 2488
Reputation: 1093
Just add this in the It works fine for me, hope this will resolve your issue.
<script>
var fl = document.getElementById('id_excel');
fl.onchange = function(e){
var ext = this.value.match(/\.(.+)$/)[1];
switch(ext)
{
case 'xls':
case 'xlsx':
alert('allowed');
break;
default:
alert('not allowed');
this.value='';
}
};
</script>
Upvotes: 1