Saturday, October 22, 2016

Asp.Net :RegularExpressionValidator to Validate MaxLength of TextMode="MultiLine" of textbox

In this post, I am discussing RegularExpressionValidator. And I am using validation expression for the multiline textbox. But this is validated on the server side.

<div class="col-md-12">
<div class="col-md-4">
Comments<span style="color: Red;">*</span>
<div class="col-md-6">
<asp:TextBox ID="txtComments" runat="server" TextMode="MultiLine" ClientIDMode="Static">
<asp:RegularExpressionValidator runat="server" ID="RegularExpressionValidator3"
ControlToValidate="txtComments" ValidationExpression="^[\s\S]{0,100}$"
ErrorMessage="Please enter a maximum of 100 characters"
Display="Dynamic" ValidationGroup="valSubmit"></asp:RegularExpressionValidator>

In the above validation expression ValidationExpression="^[\s\S]{0,maxlength}$", the max-length that you define as per your database table is required. This validation is valid for this expression on the server side.

No comments:

Post a Comment