title: How to validate email field in javascript?
body: <p>This is the script I use for form validation:</p>
  
  <pre><code>&lt;script language="JavaScript"&gt;
  
  function formCheck(formobj){
      var fieldRequired = Array("Name", "Email", "Phone", "comments");
      var fieldDescription = Array("Name", "Email", "Phone", "Comments");
      var alertMsg = "Please complete the following fields:\n";
  
      var l_Msg = alertMsg.length;
  
      for (var i = 0; i &lt; fieldRequired.length; i++){
          var obj = formobj.elements[fieldRequired[i]];
          if (obj){
              switch(obj.type){
              case "select-one":
                  if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
                      alertMsg += " - " + fieldDescription[i] + "\n";
                  }
                  break;
              case "select-multiple":
                  if (obj.selectedIndex == -1){
                      alertMsg += " - " + fieldDescription[i] + "\n";
                  }
                  break;
              case "text":
              case "textarea":
                  if (obj.value == "" || obj.value == null){
                      alertMsg += " - " + fieldDescription[i] + "\n";
                  }
                  break;
              default:
              }
              if (obj.type == undefined){
                  var blnchecked = false;
                  for (var j = 0; j &lt; obj.length; j++){
                      if (obj[j].checked){
                          blnchecked = true;
                      }
                  }
                  if (!blnchecked){
                      alertMsg += " - " + fieldDescription[i] + "\n";
                  }
              }
          }
      }
  
      if (alertMsg.length == l_Msg){
          return true;
      }else{
          alert(alertMsg);
          return false;
      }
  }
  // --&gt;
  &lt;/script&gt;
  
  
  &lt;form onsubmit="return formCheck(this);" action="/capture.weblead" method="post"&gt;
  First Name: &lt;input type=text name="FirstName" size="25"&gt;&lt;br&gt;
  Last Name: &lt;input type=text name="LastName" size="25"&gt;&lt;br&gt;
  &lt;input type=submit value="Submit Form"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>It works great except it doesn't validate for a REAL email address. How to alter this form so that it does?</p>
  
  <p>The script can't contain any dollar symbols otherwise Tomcat (my server environment) crashes.</p>