title: jQuery Validate File Type On Change
body: <p>I have a jQuery File Upload. That upload function is only allow image type. <code>.jpg, .gif, .png</code></p>
  
  <p>Assume I have 2 file, that's a.jpg &amp; b.pdf. Now, I change the extension b.pdf to be b.jpg</p>
  
  <p>a.jpg is original image.<br>
  b.jpg is not an original image.</p>
  
  <p>My question, how can I validate that b.jpg is not an original image?</p>
  
  <p>Here is my JS script :</p>
  
  <pre><code>$(function()
  {
      $("#file").change(function()
      {
          var file = this.files[0];
          var imagefile = file.type;
          var match= ["image/jpeg","image/png","image/jpg"];
          var file_size = this.files[0].size;
  
          if(!((imagefile==match[0]) || (imagefile==match[1]) || (imagefile==match[2])))
          {
              alert("Invalid File");
          }
          else
          {
              var reader = new FileReader();  
  
              reader.onload = imageIsLoadeds;
              reader.readAsDataURL(this.files[0]);
          }
  
          function imageIsLoadeds(e)
          {
              if(file_size&gt;=1024000)
              {
                  alert("File Size Error");
              }
              else
              {
                  $('#image').attr('src', e.target.result);
              }
          }
      }
  }
  </code></pre>