how to validate image extention by javascript?
function validate()
{
var filename = document.getElementById("pimage").value;
if(filename!='')
{
var ext = getExt(filename);
if(ext == "jpg" || ext == "jpeg" || ext == "gif" || ext == "png" || ext == "")
return true;
alert("Please upload image files only.");
return false;
}
}
function getExt(filename)
{
var dot_pos = filename.lastIndexOf(".");
if(dot_pos == -1)
return "";
return filename.substr(dot_pos+1).toLowerCase();
}
}
{
var filename = document.getElementById("pimage").value;
if(filename!='')
{
var ext = getExt(filename);
if(ext == "jpg" || ext == "jpeg" || ext == "gif" || ext == "png" || ext == "")
return true;
alert("Please upload image files only.");
return false;
}
}
function getExt(filename)
{
var dot_pos = filename.lastIndexOf(".");
if(dot_pos == -1)
return "";
return filename.substr(dot_pos+1).toLowerCase();
}
}
Comments
Post a Comment