title: javascript only allow alphanumeric and hyphen - value in text field
body: <p>I have a text field, whose value I am reading. I want to only allow alphanumeric characters and hyphen - value.</p>
  
  <p>The regex I have so far doesn't seem to fire if I enter values like abc$d or w2w,2 or we&amp;*23 etc.</p>
  
  <pre><code>var someName = document.getElementById("sometextField");
  if(/^[a-z0-9-]+$/i.test(someName.value))
  {
      alert('Name can only be alpha numeric with hypen.');
      return;
  }
  </code></pre>
  
  <p>Please help. Thanks for your help and time.</p>