title: Form onSubmit validation not working
body: <p>I want to use javascript to validate my form's input before sending the data to the php file. I tried using <code>onSubmit</code>, but for some reason the javascript function is getting skipped over and the data is going straight to the php file. I'm not sure what's wrong with my code- I'd initially put the javascript in another file, then I included it in the page itself with a <code>&lt;script&gt;</code> tag, it's still not working. Here's my code-</p>
  
  <p>The form-</p>
  
  <pre><code>&lt;form action="includes/register.inc.php" name="registration_form" method="post" onSubmit="return regform(this.form,
   this.form.first-name, this.form.last-name, this.form.signup-username, this.form.signup-email, 
  this.form.signup-password, this.form.confirm-password);"&gt;
  
      &lt;input id="first-name" name="first-name" type="text" placeholder="First Name"/&gt;
      &lt;input id="last-name" name="last-name" type="text" placeholder="Last Name"/&gt;
      &lt;input id="signup-username" name="signup-username" type="text" placeholder="Username"/&gt;
      &lt;input id="signup-email" name="signup-email" type="email" placeholder="E-mail"/&gt;
      &lt;input id="signup-password" name="signup-password" type="password"  placeholder="Password"/&gt;
      &lt;input id="confirm-password" type="password" name="confirm-password" placeholder="Confirm Password"/&gt;
  
      &lt;input type="submit" value="CREATE ACCOUNT"/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Javascript-</p>
  
  <pre><code>function regform(form, fname, lname, uid, email, password, conf) {
   // Check each field has a value
  if (uid.value == ''         || 
        email.value == ''     || 
        password.value == ''  || 
        fname.value == ''     ||
        lname.value == ''     ||
        conf.value == '') {
  
      alert('You must provide all the requested details. Please try again');
      return false;
  }
  
  // Check the username
  
  re = /^\w+$/; 
  if(!re.test(uid.value)) { 
      alert("Username must contain only letters, numbers and underscores. Please try again"); 
  
      return false; 
  }
  
  var alphaExp = /^[a-zA-Z\-]+$/;
  if(!fname.value.match(alphaExp)) { 
      alert("First name must contain only letters and hyphens. Please try again"); 
  
      return false; 
  }
  
  if(!lname.value.match(alphaExp)) { 
      alert("First name must contain only letters and hyphens. Please try again"); 
  
      return false; 
  }
  
  // Check that the password is sufficiently long (min 6 chars)
  // The check is duplicated below, but this is included to give more
  // specific guidance to the user
  if (password.value.length &lt; 6) {
      alert('Passwords must be at least 6 characters long.  Please try again');
  
      return false;
  }
  
  // At least one number, one lowercase and one uppercase letter 
  // At least six characters 
  
  var re = /(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}/; 
  if (!re.test(password.value)) {
      alert('Passwords must contain at least one number, one lowercase and one uppercase letter.  Please try again');
      return false;
  }
  
  // Check password and confirmation are the same
  if (password.value != conf.value) {
      alert('Your password and confirmation do not match. Please try again');
  
      return false;
  }
  
  
  // Finally submit the form. 
  return true;
  }
  </code></pre>