title: Checking the format of an email address in a contact form
body: <p>I'm using a simple form with a name, email and comment field to send messages from a webpage. There's a hidden title field as well which should be empty in order for the form to be submitted - spam protection if you like. </p>
  
  <p>The JQuery code I am running the form through before submitting works ok, but is currently only looking for an "@" character in the email address field. What I want is a better check for a correctly formatted email address.</p>
  
  <p>Here's the code.</p>
  
  <pre><code>    $(function() {  
      $('.error').hide();  
      $(".button").click(function() {  
      // validate and process form here  
  
          $('.error').hide();  
          var name = $("input#name").val();  
              if (name == "") {  
              $("label#name_error").show();  
              $("input#name").focus();  
              return false;
          }  
          var email = $("input#email").val();  
              if (!(email.indexOf('@') &gt; 0)) {
              $("label#email2_error").show();  
              $("input#email").focus();  
          return false;  
          }  
          var message = $("textarea#message").val();  
              if (message == "") {  
              $("label#message_error").show();  
              $("textarea#message").focus();  
          return false;  
          } 
          var title = $("input#title").val()
              if(title !== "") {  
              $("input#title").focus();  
          return false;  
          } 
  
      var dataString = 'name='+ name + '&amp;email=' + email + '&amp;message=' + message;  
      //alert (dataString);return false;  
      $.ajax({  
          type: "POST",  
          url: "sendmail.php",  
          data: dataString,  
          success: function() {  
              $('#message_form').html("&lt;div id='response'&gt;&lt;/div&gt;");  
              $('#response').html("&lt;div id='content_success_block' class='shadow_box'&gt;")  
                  .append("&lt;div id='success_image'&gt;&lt;img src='assets/misc/success.png'&gt;&lt;/div&gt;")
                  .append("&lt;div id='success_text'&gt;Thanks for contacting us! We will be in touch soon.&lt;/div&gt;")
                  .append("&lt;/div&gt;")                   
              .hide()  
              .fadeIn(2500, function() {  
                  $('#response');  
              }); 
          }  
      });  
      return false; 
      });
  
  });
  </code></pre>
  
  <p>Any help is appreciated. </p>