Limiting the # of characters – ASP.NET

If you want to limit the number of characters in a text field use the code below:

< asp:TextBox runat="server" ID="Body" TextMode="MultiLine" MaxLength="5" Columns="55"
Rows="10" BackColor="#FFCC99" Width="346px"
style="background-color: #FFF0E1">
< asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
ControlToValidate="Body" Display="Dynamic"
ErrorMessage="25 characters maximum including spaces"
ValidationExpression="^[sS]{0,25}$" style="font-size: x-small" />