title: Javascript validation
body: <p>Please help me. The validation is notworking</p>
  
  <pre><code>&lt;script type="text/javascript"  src="javascript.js"&gt;
  function validation()
  {
      var fname=document.forms["form1"]["fname"].value;
      var lname=document.forms["form1"]["lname"].value;
      var idnumber=document.forms["form1"]["idnumber"].value;
      var email=document.forms["form1"]["email"].value;
      var atpos=email.indexOf("@");
      var dotpos=email.lastIndexOf(".");
      var address=document.forms["form1"]["address"].value;
      var phonenumber=document.forms["form1"]["phonenumber"].value;
  
      if (fname==null || fname=="")
      {
          alert("Name should be entered correctly");
          return false;
      }
  
      if (lname==null || lname=="")
      {
          alert("Name should be entered correctly");
          return false;
      }
  
      if (isNaN(idnumber))
      {
          alert("Please enter a valid id number");
          return false;
      }
  
      if (atpos&lt;1 || dotpos&lt;atpos+2 || dotpos+2&gt;=x.length)
      {
          alert("Please enter a valid e-mail address");
          return false;
      }
  
      if(address==null || address=="")
      {
          alert("Please insert your address");
          return false;
      }
      if (isNaN(phonenumber))
      {
          alert("Please enter a valid phone number");
          return false;
      }
  
  
  }
  &lt;/script&gt;
  &lt;form name="form1" action="validation.php" method="post"  onsubmit=" return validation(this);return false"&gt; 
     Firstname:&lt;input type="text" name="fname"&gt;&lt;br/&gt;
     Lastname:&lt;input type="text" name="lname"&gt;&lt;br/&gt;
     Nation ID Number:&lt;input type="text" name="idnumber"  minlength="8"maxlength="8"&gt;&lt;br/&gt;
     Email address: &lt;input type="text" name="email"&gt;&lt;br/&gt;
     Address:&lt;input type="text" name="address"&gt;&lt;br/&gt;
     Pnone number:&lt;input type="text" name="phonenumber"&gt;&lt;br/&gt;
     &lt;input type="reset" name="reset" value="reset"&gt;
     &lt;input type="submit" name="submit" value="submit"&gt;
  &lt;/form&gt;
  </code></pre>