DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
File Extension Validation In Asp.net
// file extension validation in asp.net
function ValidateFileUploaded() {
var frm = document.forms[0];
var fileExtension;
var isValid = true;
var flag = false;
var cnt = 0;
var allowedFileType;
allowedFileType= '.xls';
for (i = 0; i < frm.elements.length; i++) {
if (frm.elements[i].type == "file") {
extension = frm.elements[i].value.substring(frm.elements[i].value.lastIndexOf('.')).toLowerCase();
if (frm.elements[i].value != "") {
if (fileExtension != allowedFileType) {
isValid = false;
break;
}
}
}
}
if (isValid) {
return true;
}
else {
alert("Only " + allowedFileType+ " files can be uploaded.");
return false;
}





