title: Javascript regex only alphabet, number and underscore
body: <p>I want to check if a text box input is valid (only alphabet, numbers and underscores allowed. No whitespaces or dashes). I currently have this, but whitespaces &amp; dashes seem to pass.</p>
  
  <pre><code>function validText(field)
  {
      var re = /[a-zA-Z0-9\-\_]$/
      if (field.value.search(re) == -1)
      {
          alert ("Invalid Text");
          return false;
      }
  }
  </code></pre>
  
  <p>A valid input would be something like </p>
  
  <p>'<code>Valid_Input123</code>'</p>
  
  <p>invalid</p>
  
  <pre><code>'Invalid-Input !'
  </code></pre>