title: Submitting form even when validation regex is wrong
body: <p>i am having this problem when i submit the form where both the password and username is wrong. I get an alert box saying that i have enter the wrong details. But when the username is correct and password is validation is wrong it will give me an arlet box by when pressed ok it will submit the form even when i have returned false.
  Help please much appreciated     </p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      function validate(form_id, firstName, password){
          var Reg = /^[A-Za-z0-9_]{1,20}$/;
          var Reg1 = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[0-9a-zA-Z]{8,}$/;
          var username = document.forms[form_id].elements[firstName].value;
          var password = document.forms[form_id].elements[password].value;
  
          if (Reg.test(username) == false) {
              alert('Invalid Username.');
              document.forms[form_id].elements[firstName].focus();
              return false;
          }
  
          if (Reg1.test(password) == false) {
              alert('Invalid Password.');
              document.forms[form_id].elements[password].focus();
              return false;
          }
      }
  &lt;/script&gt;
  
  &lt;form id="form_id" action="userlogininput.cgi" onsubmit="javascript:return validate('form_id','firstName','password');"  name="form" method="post"&gt;
      Username : &lt;input type="text" id="firstName" name="firstName" class="textboxH-300" required&gt;&lt;br&gt;
      Password : &lt;input type="password" id="password" name="password" class="textboxH-300" required&gt;&lt;br&gt;&lt;br&gt;
      &lt;input id="submitbtn" type="submit" value="Submit"/&gt;
  &lt;/form&gt;
  </code></pre>