Validation on button
<p>I'm doing validation first on an email(mandatory and correct format) and then on a file upload(either blank or correct format) on the button submit.<br>
Here the email is validating well but in file upload if it is blank it also shows an error which is not needed.</p>

<p>Code:</p>

<pre><code>&lt;script type="text/javascript"&gt;

    $(document).ready(function () {

     $("#button").click(function () {

         var email = $("#person_email").val();
         var img = $("#person_avatar").val();

         if (email == null || email == "" || !email.match(/^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$/))

         {
             $("#valid").show();
             return false;

         } else if (!img == "" || !img.match(/(\.bmp|\.png|\.jpg|\.jpeg|\.gif)$/))

         {
             $("#valid_1").show();
             return false;
         } else {
             return true;
         }
     });
 });
&lt;/script&gt;
</code></pre>
