title: How To stop Submit If we selected wrong file in php
body: <blockquote>
    <p>I want To stop Form submit if i have selected wrong file in input
    file through js validation or from any other method .currently when i
    selected word file through file field it submit the form but return me
    the alert that this kind of file u can not upload and remove the input
    fields value how can i stop this ..</p>
  </blockquote>
  
  <p>And js to stop wrong image file but its not working::</p>
  
  <pre><code>$("#profile_pic").change(function () {
    var fileExtension = ['jpeg', 'jpg', 'png', 'gif'];
    if ($.inArray($(this).val().split('.').pop().toLowerCase(), fileExtension) == -1) {
        alert("Only formats are allowed : "+fileExtension.join(','));
         return false;
    }
  });
  </code></pre>