For the exact length of the string, you could use
^.{50}$
Whereas to check the length range you can use
^.{5,50}$
It might be more sensible for real users if I also included a lower limit on the number of letters.
If you wanted to just check the minimum length you can use
^.{50,}$
Now a string of at least fifty letters, but extending to any length,
^.{0,50}$
This will match a whole string containing between 0 and 50 (inclusive) of any character. Though regular expressions are probably the wrong tool for this job. Regex is overkill; just check the length of the string. You should have used String.Length
for this, like:
if(UrString.Length > 0 && UrString.Length <= 50)
.
will match any one character, so^.{1,50}$
^.{1,50}$
- you missed the dot. But I'm pretty sure that C# has methods to check string length without using regex.MyString.Length <= 50
?