I am wanting to validate user input on a text box by only allowing (white space, letter, or digit, '-' and '_'). I was wondering if someone could help me with that regexp? I found this SO question, but i am trying it and it is not working.
Here is what i am using:
if (!System.Text.RegularExpressions.Regex.IsMatch(NameTextBox.Text, "/^([a-zA-Z])([a-zA-Z0-9_ -])$/"))
Thanks.
EDIT - New approach.
I actually decided to go with this instead of regex, any reason why i should not?
if (!NameTextBox.Text.All(c=>Char.IsLetterOrDigit(c) || c==' ' || c=='_' || c=='-'))