title: How do I check that a string doesn't include any characters other than letters and numbers?
body: <p>This is what I have so far, but I can't find anywhere the code to say that I just want to include letters and numbers. I'm not familiar with regular expressions. Right now my code just ignores the while loop even if I include '#'.</p>
  
  <pre><code>public partial class Form1 : Form
  {
      public Form1()
      {
          InitializeComponent();
  
      }
  
      private void okBtn_Click(object sender, EventArgs e)
      {
          if(textBox1.Text.Contains(@"^[^\W_]*$"))
          {
              fm1.txtFileName = textBox1.Text;
              this.Close();
          }
          else
          {
              MessageBox.Show("Filename cannot include illegal characters.");
          }
      }
  }
  </code></pre>