want to get a validation script to validate the file upload box onsubmit.
check the extension of the file and validate accordingly to the extension of file loaded
want to get a validation script to validate the file upload box onsubmit.
check the extension of the file and validate accordingly to the extension of file loaded
If you don't mind jquery, then you can use the validation plugin, which is available here. A brief introduction and small demo is available here.
Check here: http://jsfiddle.net/uh2Gn/
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;
}
}
Keep in mind that this is only for user convenience, that he doesn't go theu a long submit process to get an error at the server, cuz for sure you must implement a check at server-side.