title: Make sure string only contains certain characters in C#
body: <p>I have a string and I want to make sure it only contains characters in <code>BSEO|0123456789</code>. I tried to do that with this regex</p>
  
  <pre><code>Regex r = new Regex("^[BSEO|0123456789]");
  if (r.IsMatch(str)) throw new Exception("Invalid character.");
  </code></pre>
  
  <p>but it doesn't behave correctly, (e.g. string <code>SE</code> throws exception). What am I doing wrong, how can I fix it, and is there a better solution to this than using regex?</p>