ASP Regular Expression Validator for Multi-line textbox

I need to validate the length of input of a textbox.

The max length property does not work for Multiline textboxes.

The regular expression I have is:

<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
                            ErrorMessage="The notes has exceeded maximum length."
                            ControlToValidate="txtNotes" Display="Dynamic"
                            ValidationExpression=".{0,500}" ValidationGroup="PO">
                            *</asp:RegularExpressionValidator>

The problem I’m having is when a new line is entered into the textbox the validator reports a problem.

What would I need to add to the ValidationExpression to ignore carriage returns?

Thanks

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Change .{0,500} to [sS]{0,500}. Note that carriage returns won’t exactly be ignored; they’ll still count toward the 500-character limit.

Of course, if 500 characters is the size of your database field, that’s exactly the behavior you want.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x