JSFiddle - React, Tailwind, and code Playground
HTML
<form method="post" enctype="" onsubmit="return validate()">
<input type="file" id="file" />
<input type="submit" />
</form>
JavaScript
function validate() {
var filename=document.getElementById('file').value;
var extension=filename.substr(filename.lastIndexOf('.')+1).toLowerCase();
//alert(extension);
if(extension=='jpg' || extension=='gif') {
return true;
} else {
alert('Not Allowed Extension!');
return false;
}
}