I have the following regular expression which specifies characters the user is allowed to type:
@"^[A-Za-z0-9/!\$%\^&\*\(\)\-_\+\[\]\{\}\;\:\'\£\@\#\.\?]*$
I know ‘\s‘ is the character class for white space, but how do I add this to the regular expression so it excludes it? I have searched for this on Stack Overflow – the questions provide solutions to exclude white space but not how to use it in an existing regular expression. If I add it like I have the other characters, it would mean ‘allow white space’?
Edit: Not sure why this has been marked down? Thanks to everyone for their answers
First of all, you don’t need all those escapes.
Second of all, the regex already doesn’t allow whitespaces.
The [] define a set of characters to allow (followed by * means that characters from the characters set can be zero or more times).
^ matches the beginning and $ matches the end, so the fact that /s isn’t anywhere there, means white spaces won’t be allowed.