Wednesday, March 7, 2012

How to check file upload image validation in javascript?


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Image Extension Validation</title>
</head>
<script type="text/javascript" language="javascript">
//Image Extension Validation
function img_path()
{
var file_path=document.getElementById('file').value;
if(file_path.match(".jpeg$")==".jpeg" || file_path.match(".gif$")==".gif" || file_path.match(".GIF$")==".GIF" || file_path.match(".JPEG$")==".JPEG" || file_path.match(".JPG$")==".JPG" ||file_path.match(".jpg$")==".jpg")
{
return true;
}
else
{
alert("Upload  .jpg/.gif  file olny");
return false;
}

}
</script>
<body>
<form name="image" enctype="multipart/form-data" method="post" >
<table width="568" cellspacing="0" cellpadding="0" >
     <tr >
              <td colspan="2"   valign="top" >&nbsp;</td>
     </tr>
 <tr>
 <td width="126" align="left" valign="top">File Choose*</td>
<td width="310"  align="left" valign="top" style="padding-left:10px;">
  <input type="file" name="file" id="file" style="height:22px;">
               <input name="submit" type="submit" value="Upload" onClick="return img_path()">
</td>
</tr>
</table>
</form>

</body>
</html>


1 comment:

  1. Decent Post with data in regards to extraordinary utilize! The ways you have delineated the data is amazing. Much obliged!
    Website Developers Bangalore | Web Development Company In Bangalore

    ReplyDelete