Sibusiso Shongwe Sibusiso Shongwe - 25 days ago 7
ASP.NET (C#) Question

How to use the ASP.NET Regular expression validator

I am trying to set the minimum number of characters for a textbox, and if the user input dos not reach the set minimum an error must show, In i was trying to do just that using

<asp:RegularExperssionValidator>
but the error message is nit showing, what am i missing or doing wrong?

<asp:TextBox ID="TextBox2" runat="server" CssClass="form-control"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ErrorMessage="ID length is Less than 10" ControlToValidate="TextBox2" ValidationExpression=".{10}.*">
</asp:RegularExpressionValidator>




`

Answer
<asp:TextBox ID="TextBox2" runat="server" CssClass="form-control"></asp:TextBox> 
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
ErrorMessage="ID length is Less than 10" ControlToValidate="TextBox2" ValidationExpression="^[a-zA-Z0-9]{10,1000}$">
</asp:RegularExpressionValidator>
  <br />
  <asp:Button ID="Button1" runat="server" Text="Button" />
Comments