ASP.NET has no build in validator for textbox or multiline textbox length validation. But it can be done using RegularExpressionValidator validator.
SourceCode:
Using RegularExpressionValidator to validate max length in ASP.NET
To validate max length using regular expression you can use this regular expression pattern(\s|.){0,1024}$it matches text length from 0 to 1024 and if text length is more than 1024 this validator display error message to user.
SourceCode:
<asp:TextBox ID="txtProjectInfo" runat="server" Rows="4" TextMode="MultiLine"></asp:TextBox>
<asp:RegularExpressionValidator ID="maxLenProjectInfo" ControlToValidate="txtProjectInfo"
ValidationExpression="(\s|.){0,1024}$" ErrorMessage="Project info is too long. Max length is 1024."
runat="server" />
No comments:
Post a Comment