title: implementing server-side regex validation from client-side regex
body: <p>I have a textbox into which I only want alphanumeric characters and some punctuation; the <a href="http://jsfiddle.net/kgDZk/" rel="nofollow"><strong>jsFiddle</strong></a> is here and the javascript implementation looks like this:</p>
  
  <pre><code>var TheCleanString = TheInput.replace(/(^\s+|[^a-zA-Z0-9 \\s\(\)\.\-]+)/g, '');
  </code></pre>
  
  <p>As you can see, this only allows for alphanumeric characters, removes the leading whitespace and allows for parenthesis, dots and hyphens.</p>
  
  <p>Now I want to use the SAME regex to validate that the string that's coming from the client passed this regex. I have something like this:</p>
  
  <pre><code>public bool MadeIt(TheCandidateString) 
  {
     if (TheCandidateString passed this
         regex /(^\s+|[^a-zA-Z0-9 \\s\(\)\.\-]+)/g 
         then return true)
  }
  </code></pre>
  
  <p>What's the best way to do this?</p>
  
  <p>Thanks.</p>