validating fileupload control in Javascript

Pavanandey
Posted by Pavanandey under JavaScript category on | Points: 40 | Views : 1035
function checkFileLength(elem,obj)
{

var filePath = elem.value;

if(filePath == "")
{
alert("Please select file to upload.");
return false;
}
else
{
if(filePath.indexOf('.') == -1)
return false;

var validExtensions = new Array();
var ext = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase();

validExtensions[0] = 'pbd';
validExtensions[1] = 'jpeg';
validExtensions[2] = 'bmp';
validExtensions[3] = 'gif';
validExtensions[4] = 'png';
validExtensions[5] = 'xml';
validExtensions[6] = 'tif';
validExtensions[7] = 'mdf';
validExtensions[8] = 'pdf';
validExtensions[9] = 'jpg';

for(var i = 0; i < validExtensions.length; i++) {
if(ext == validExtensions[i])

return true;
}

alert('Invalid file format.');
var who=obj;

who.value="";var who2= who.cloneNode(false);
who2.onchange= who.onchange;

who.parentNode.replaceChild(who2,who);

return false;
}
}


function checkFile()
{
var elm=null;
elm=getObj("ctl00_ContentPlaceholder1_fileItemImage");
if(!checkFileLength(elm,elm))
return false;
else
return true;
}

Comments or Responses

Login to post response