title: Check if a string contains only letters, digits and underscores
body: <p>I have to check if a string contains only letters, digits and underscores.
  This is how I tried but it doesn't work:</p>
  
  <pre><code>for(int i = 0; i&lt;=snameA.Length-1; i++)
  {
      validA = validA &amp;&amp; (char.IsLetterOrDigit(snameA[i])||snameA[i].Equals("_"));
  }
  </code></pre>