title: C# Regex for invalid characters
body: <p>Hi I have a requirement to validate an input that should accept only alphanumeric, -, _ 
  To test this i am using the following code</p>
  
  <pre><code> string pattern = @"[^a-z A-Z 0-9._-]$";
          var matches = Regex.Matches(m_ModelName.Value, pattern, RegexOptions.IgnoreCase);
          return (matches.Count &gt; 0);
  </code></pre>
  
  <p>if the count is >0 it means there are invalid characters. But it never returns according to my expectations. Please tell me what I am doing wrong. This is strictly c#</p>