Wednesday, 11 September 2013

ASP.Net Regular Expression Validation of String Length

ASP.Net Regular Expression Validation of String Length

I want to validate if the string entered by user into a text box is at
least 3 characters long. I was using following regex:
\w{3,40}
But it fails if user enters say:
my valid string
I want something that will validate the total string length including
spaces between the words but not at end or beginning of the string.
So following are valid:
"a bc"
"a b c"
"abc"
"a b c"
but following are not:
"a b "
" a "
" bc"

No comments:

Post a Comment