如何使用ASP.. NET正则表达式验证器

本文关键字:验证 正则表达式 NET 何使用 ASP | 更新日期: 2023-09-27 18:16:37

我正在尝试设置文本框的最小字符数,如果用户输入没有达到设置的最小错误必须显示,在我试图做的只是使用<asp:RegularExperssionValidator>,但错误消息是不显示,我错过了什么或做错了?

<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>

                `

如何使用ASP.. NET正则表达式验证器

<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" />