I was shown the following:
[RegularExpression(@"\b*[a-zA-Z0-9_]\b", ErrorMessage = "Enter a single work account name please")]
But it seems to give an error when a string contains more than one character. Can someone help with a Regex that checks if there is more than one word in a string?
^[a-zA-Z0-9_]+$
Word boundaries \b
do not work here, as the pattern will match for each word.
If you want to allow non-Latin characters, you can use the shorthand version:
^\w+$
There was only missing one single piece to your regex
@"^\b[a-zA-Z0-9_]+\b$"
you forgot to state that the character could be repeated more than 1 time. That's the reason for the plus sign, so that it may accept only 1 word
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With