Reputation: 9027
I have a textbox and need to limit number of characters in it (no more than 1000).
This is the regular expression i have: ^.{0,1000}$
it works great until there is a newline in a textbox (when I hit enter). If there is newline in textbox it shows me the warning "you have more than 2000 characters". Is there workaround of this issue.
Upvotes: 1
Views: 519
Reputation: 888213
Set the RegexOptions.SingleLine
flag.
Alternatively, you could explicitly include newlines in the regex: ^(\n|.){0,1000}$
Upvotes: 1
Reputation: 156055
.
doesn't match all characters (i.e. newlines), so you can use two characters groups to get all characters, like this:
^[\s\S]{0,1000}$
Upvotes: 3