title: javascript regex (username validation)
body: <p>I want to enforce that </p>
  
  <ol>
  <li>the input firstname should only contains characters A-Z, a-z, and -</li>
  <li>the input login name should only contains alphanumeric characters</li>
  </ol>
  
  <p>How do I restrict the two rules in javascript?</p>
  
  <p>Below is my code (jsp) for username regex. But it's not working properly.</p>
  
  <pre><code>function validateForm(){
      var nameRegex = /^[a-zA-Z\-]+$/;
      var validfirstUsername = document.frm.firstName.value.match(nameRegex);
      if(validUsername == null){
          alert("Your first name is not valid. Only characters A-Z, a-z and '-' are  acceptable.");
          document.frm.firstName.focus();
          return false;
      }
  }
  </code></pre>
  
  <p>Thanks!</p>