Friday, May 2, 2008

Check file extention and validate Client side easily- Sanjeewa sapumana

<script language="javascript" type="text/javascript">

/*To check file extensions */
function checkFileExtension( s,e ){
parafilevalue =document.getElementById("FileUpload1").value
var file = parafilevalue.split('.');

var validType = false;

if( file.length < 2 )
{
return false;
}

var fileext = file[1].toLowerCase();

if( fileext == 'doc' || fileext == 'pdf'|| fileext == 'xls' || fileext == 'ppt'|| fileext == 'txt' )
{
validType = true;
}
if(validType==false)
{
alert("Please enter specified document type");
var who= document.getElementsByName('FileUpload1')[0];
var who2= who.cloneNode(false);
who2.onchange = who.onchange;
who.parentNode.replaceChild(who2,who);
}
return validType;

}
< /script >

No comments: