Multiline TextBox Maximum Character Validation

Multiline TextBox Maximum Character Validation

Maximum character validation on asp.net TextBox controls do not work, therefore a RegularExpressionValidator has to be used to make sure the maximum number of characters are not exceeded e.g.

<asp:TextBox ID=”tbAbstract” runat=”server” Text='<%# Bind(“Abstract”) %>’ Rows=”5″ TextMode=”MultiLine” MaxLength=”4000″/>
<asp:RegularExpressionValidator ID=”valAbstract” runat=”server” EnableClientScript=”false” ControlToValidate=”tbAbstract” Text=”Abstract exceeds 4000 characters” Display=”Dynamic” SetFocusOnError=”true” ToolTip=”Abstract must not exceed 4000 characters” ValidationExpression=”^[sS]{0,4000}$” />

In the above example the validation expression regular expression checks for any whitespace or non-whitespace characters for 0 to 4000 repetitions.

Leave a Reply

Your email address will not be published. Required fields are marked *