I have a textbox into which I only want alphanumeric characters and some punctuation; the JSFiddle is here and the JavaScript implementation looks like this:
var TheCleanString = TheInput.replace(/(^\s+|[^a-zA-Z0-9 \\s\(\)\.\-]+)/g, '');
As you can see, this only allows for alphanumeric characters, removes the leading whitespace and allows for parenthesis, dots and hyphens.
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:
public bool MadeIt(TheCandidateString)
{
if (TheCandidateString passed this
regex /(^\s+|[^a-zA-Z0-9 \\s\(\)\.\-]+)/g
then return true)
}
What's the best way to do this?