title: How to validate form which accepts only (any)image type files?
body: <p>Here i have demo.jsp page where i'm uploading the image for this i have written javascript validation code for jpg,png and gif but if image type is other than that we cant write for every type in conditon so is there any alternate method to do this?</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
      &lt;title&gt;ImageResizing&lt;/title&gt;
      &lt;script&gt;
          function  vlidate() {
              var fileName = document.getElementById("Imgfile").value;
              var file_extension = fileName.split('.').pop();
              var newWidth = document.getElementById("newWidth").value;
              var newHeight = document.getElementById("newHeight").value;
              //alert(fileName);
              //alert(file_extension);                
              if (file_extension !== "jpg" || file_extension !== "png" || file_extension !== "gif") {
                  alert("Choose Valid image");
              }
              else if ((file_extension == "jpg" || file_extension == "png" || file_extension == "gif") &amp;&amp; (newWidth.length != "" &amp;&amp; newHeight.length != "")) {
                  //alert("Go ahead");
                  document.getElementById("uploadImgForm").submit();
              }
          }
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body bgcolor="#ABD3EB"&gt;
      &lt;%
          out.println("&lt;form method='post' action='FileUploadServlet' enctype='multipart/form-data' id='uploadImgForm' name='uploadImgForm'&gt;");
          out.println("&lt;h2&gt;Image Resizing&lt;/h2&gt;");
          out.println("&lt;table&gt;");
          out.println("&lt;tr&gt;&lt;td&gt;&lt;input type='file' id='Imgfile' name='Imgfile'&gt;&lt;/td&gt;&lt;/tr&gt;");
          out.println("&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;");
          out.println("&lt;tr&gt;&lt;td&gt;New Width:&lt;/td&gt;&lt;td&gt;&lt;input type='text'  id='newWidth' name='newWidth'&lt;/td&gt;&lt;/tr&gt;");
          out.println("&lt;tr&gt;&lt;td&gt;New Height:&lt;/td&gt;&lt;td&gt;&lt;input type='text' id='newHeight' name='newHeight'&lt;/td&gt;&lt;/tr&gt;");
          out.println("&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;");
          out.println("&lt;tr&gt;&lt;td&gt;&lt;input type='button' value='Upload Image' onclick='vlidate()' &gt;&lt;/td&gt;&lt;/tr&gt;");
          //out.println("&lt;tr&gt;&lt;td&gt;&lt;input type='submit' value='Upload Image' &gt;&lt;/td&gt;&lt;/tr&gt;");
          out.println("&lt;/table&gt;");
          out.println("&lt;/form&gt;");
      %&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p></p>