title: How to check for special characters using regex
body: <p>NET. I have created a regex validator to check for special characters means I donot want any special characters in username. The following is the code </p>
  
  <pre><code>Regex objAlphaPattern = new Regex(@"[a-zA-Z0-9_@.-]");
              bool sts = objAlphaPattern.IsMatch(username);
  </code></pre>
  
  <p>If I provide username as    $%^&amp;<em>asghf  then the validator gives as invalid data format which is the result I want but If I provide a data   s23_@.-^&amp;</em>()%^$#  then my validator should block the data but my validator allows the data which is wrong</p>
  
  <p>So how to not allow any special characters except a-z A-A 0-9 _ @ .-</p>
  
  <p>Thanks
  Sunil Kumar Sahoo</p>