title: Javascript regex email validation
body: <p>I have used regex to test for the email input. It does give an alert when a wrong email (for eg without an @ or .com) is submitted but when I press ok for the alert, it still posts the email to the email address that is am directed to the page send_msg.php when it should not.. I am quite new to Javascript and PHP so I am still learning.. I know that the <em>if</em> clause should follow an <em>else</em> but I don't know how to make it post the email if it is true. And can how I make it just display a message below the email input field instead of making it raise an alert?</p>
  
  <pre><code>&lt;script&gt;
  function checkEmail(inputvalue){    
  var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
  if(pattern.test!=(inputvalue)){  
           alert("Please enter a valid email address");  
           return false;
  
  
  }
  </code></pre>
  
  <p>}
    </p>
  
  <pre><code>&lt;form id="contact-form" name= "form1 "action="send_msg.php" method="post"&gt;
          &lt;h3&gt;Get in touch&lt;/h3&gt;
          &lt;h4&gt;Fill in the form below, and we'll get back to you within 24 hours.&lt;/h4&gt;
          &lt;div&gt;
              &lt;label&gt;
                  &lt;span&gt;Name: &lt;/span&gt;
                  &lt;input placeholder="Please enter your name" name="name" type="text" tabindex="1" required autofocus&gt;
              &lt;/label&gt;
          &lt;/div&gt;
          &lt;div&gt;
              &lt;label&gt;
                  &lt;span&gt;Email: &lt;/span&gt;
                  &lt;input placeholder="Please enter your email address" name="email" type="email" tabindex="2" required&gt;
              &lt;/label&gt;
          &lt;/div&gt;
  
          &lt;div&gt;
              &lt;label&gt;
                  &lt;span &gt;Message: &lt;/span&gt;
                  &lt;textarea placeholder="Include all the details you can" name="message" tabindex="5" size= "35" maxlength= "255"&gt;&lt;/textarea&gt;
              &lt;/label&gt;
          &lt;/div&gt;
          &lt;div&gt;
              &lt;button name="submit" type="submit" onClick="checkEmail(document.contact-form.email.value)" id="contact-submit"&gt;Send Email&lt;/button&gt;
          &lt;/div&gt;
      &lt;/form&gt;
  </code></pre>