With the help of this example, we are going to validate image extension suing JavaScript. JavaScript is used for client side validation. Before transferring the image to server we need to check the image extension so that client can send valid image at server with the help of submit form.
In this Example, we are using an function that will validate the image by using its extension.
In this Example, we are using an function that will validate the image by using its extension.
function validate()
{
var filename = document.getElementById("image").value;
if(filename!='')
{
var ext = getExt(filename);
if(ext == "jpg" || ext == "jpeg" || ext == "gif" || ext == "png" || ext == "")
return true;
else{
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();
}
}
If you still face any problem then contact me using contact form below. Thanks
0 comments :
Post a Comment