JSFiddle - React, Tailwind, and code Playground
by ajai jothi
HTML
<input type="file" id="uploadDoc">
JavaScript
document.getElementById('uploadDoc').onchange = function(e){
if(!validateFile(e.target.files[0])){
alert('invalid file');
e.target.value = '';
return false;
}
};
function validateFile(file){
var allowExtn = ['doc','docx','txt','pdf']; //input allowed file extn here
var fName = file.name;
var ext = fName.split('.').slice(-1).join('');
debugger;
return allowExtn.indexOf(ext)>=0;
}