title: C# - Textbox with only letters and numbers
body: <p>How can I limit my textbox to only accept numbers and letters?
  It should not even allow spaces or anything like "!", "?", "/" and so on.
  Only a-z, A-Z, 0-9</p>
  
  <p>Tried this and it did not work at all    </p>
  
  <pre><code>if (System.Text.RegularExpressions.Regex.IsMatch(@"^[a-zA-Z0-9\_]+", txtTag.Text))
  {
      txtTag.Text.Remove(txtTag.Text.Length - 1);
  }
  </code></pre>
  
  <p>Not even sure if that <code>txtTag.Text.Remove(txtTag.Text.Length - 1);</code> should be there because it makes the application crash.</p>