Check Uploaded File extension using Javascript
function CheckExtension(file) {
/*global document: false */
var validFilesTypes = ["png", "jpg", "pdf"];
// var filePath = file.value;
var ext = file.substring(file.lastIndexOf('.') + 1).toLowerCase();
isValidFile = false;
for (var i = 0; i < validFilesTypes.length; i++) {
if (ext == validFilesTypes[i]) {
isValidFile = true;
break;
}
}
if (!isValidFile) {
file.value = null;
alert(" Invalid File Format(allowed Format: .pdf .jpg .png)");
}
return isValidFile;
}
/*global document: false */
var validFilesTypes = ["png", "jpg", "pdf"];
// var filePath = file.value;
var ext = file.substring(file.lastIndexOf('.') + 1).toLowerCase();
isValidFile = false;
for (var i = 0; i < validFilesTypes.length; i++) {
if (ext == validFilesTypes[i]) {
isValidFile = true;
break;
}
}
if (!isValidFile) {
file.value = null;
alert(" Invalid File Format(allowed Format: .pdf .jpg .png)");
}
return isValidFile;
}
Comments