title: Javascript Email and Phone Validation
body: <p>Want to validate html form with one javascript function. I have the form validation, thats only validating, if the field is empty or not. I want to check if the email is correct and the phone number is numeric. Right now the form open popup alert but after entering email it stops.</p>
  
  <p>Here are my form codes</p>
  
  <pre><code>&lt;form name="appointment" method="post" onsubmit="return doValidate();"&gt;
        Name:*&lt;br /&gt;
        &lt;input type="text" name="requiredname" /&gt;
        Email:*&lt;br /&gt;
          &lt;input type="text" name="requiredemail" /&gt;
        Phone:*&lt;br /&gt;
          &lt;input type="text" name="requiredphone" /&gt;
        Appointment Date:*&lt;br /&gt;
          &lt;input type="text" name="requireddate" /&gt;
  
    Appointment Time:*&lt;br /&gt;
              &lt;input type="text" name="requiredtime" /&gt;&lt;br /&gt;&lt;br /&gt;
                &lt;input name="submit" type="submit"  value="Book Now" /&gt;           &lt;/form&gt;
  </code></pre>
  
  <p>This is the Javascript codes:-</p>
  
  <pre><code>function doValidate()
  {
  if (document.appointment.requiredname.value =="")
  {
  alert("Please put your name");
  document.appointment.requiredname.focus();
  return false;
  }
  var readmail = document.appointment.requiredemail;
  var checkatsymbol = readmail.indexof("@");
  var checkdotsymbol = readmail.lastindexof(".");
  if (readmail.value =="" || checkatsymbol&lt;1)
  {
  alert("Please put the correct email address");
  document.appointment.requiredemail.focus();
  return false;
  }
  if (document.appointment.requiredphone.value =="" )
  {
  alert("Please put your phone");
  document.appointment.requiredphone.focus();
  return false;
  }
  if (document.appointment.requireddate.value =="" )
  {
  alert("Please put your appointment date as DD/MM/YYYY");
  document.appointment.requireddate.focus();
  return false;
  }
  if (document.appointment.requiredtime.value =="")
  {
  alert("Please put your appointment time as HH:MM AM/PM");
  document.appointment.requiredtime.focus();
  return false;
  }
  return ( true );
  }
  </code></pre>