NET. I have created a regex validator to check for special characters means I donot want any special characters in username. The following is the code
Regex
Your pattern checks only if the given string contains any "non-special" character; it does not exclude the unwanted characters. You want to change two things; make it check that the whole string contains only allowed characters, and also make it check for more than one character:
^[a-zA-Z0-9_@.-]+$
Added ^
before the pattern to make it start matching at the beginning of the string. Also added +$
after, +
to ensure that there is at least one character in the string, and $
to make sure that the string is matched to the end.