Hi,
I’m trying to use regex:
if (!Regex.Match(name, "^[a-zA-Z0-9]{5,20}+$").Success)
However, it gives error: ArgumentException: parsing "^[a-zA-Z0-9]{5,20}+$" - Nested quantifier +.
When trying to escape +:
if (!Regex.Match(name, "^[a-zA-Z0-9]{5,20}//+$").Success)
it is not working - no error, but every string is invalid.
Please help.
Ryiah
2
You need to surround the expression you want to use the +
symbol on with parentheses like this:
^([a-zA-Z0-9]{5,20})+$
Here’s a version of it modified to look for whitespace in case you’re trying to support multiple words:
^([a-zA-Z0-9]{5,20}[\s]{0,1})+$
For debugging regular expressions I recommend the following site:
1 Like