Form shows mistakenly the success alert box when it has invalid input in jQuery
<p>In the script below I check if the email entered is valid. It is not the best regex but it is ok for now. Also for the moment I do not make any server side check for input. Only with this script.</p>

<p>I have this problem though:<br>
When an email is valid, and after I type an invalid email I get first the <em>Your email is not in valid format</em> and then <em>You will be notified when we launch. Thank you!</em> alert. Also the email is sent. How to fix this ?</p>

<p>Thank you</p>

<p>this is my form</p>

<pre><code>&lt;form id="myform" action="" method="POST"&gt;
                &lt;input id="subscribe" name="subscribe" class="subscribe floatLeft" type="text"&gt;
                &lt;button id="signUp" class="signUp floatRight" &gt;&lt;intro&gt;notify!&lt;/intro&gt;&lt;/button&gt;              
                &lt;div class="clear"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/form&gt;
</code></pre>

<p>and here is the script</p>

<pre><code>var signUp = function(inputEmail) {
    var isValid = true;
    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    if (!emailReg.test(inputEmail)) {
        isValid = false;
        alert('Your email is not in valid format');
    }



$("#myform").submit(function(event) {
    event.preventDefault();
    if (!isValid) {
        return false;
    } else {
        $.post('mailme.php', $("#myform").serialize(), function(data) {
            alert('You will be notified when we launch. Thank you!');

        });
        return false;
    }
});

};
</code></pre>
