【问题标题】:How to limit maximum and minimum number of text in asp.net textbox?如何限制asp.net文本框中的最大和最小文本数?
【发布时间】:2019-11-04 20:56:44
【问题描述】:

我正在尝试限制文本框字段中的文本数量。要求是固定最小长度为7,最大长度为15。

我尝试使用 asp:RegularExpressionValidator 来限制文本框中的文本数量。

这是我的代码:

<asp:RegularExpressionValidator ID="revphone" runat="server" 
    Font-Size="16px"
    ValidationExpression="^[0-9]{7,15}$" 
    ControlToValidate="txtphonenumber" 
    ErrorMessage="*" 
    ValidationGroup="reg" 
    Display="Dynamic" 
    ForeColor="Red">
</asp:RegularExpressionValidator>Phone Number      
<asp:TextBox ID="txtphonenumber" runat="server" 
    placeholder="Phone Number" 
    Width="305px" 
    onblur="BtnRegisterClick()" 
    MaxLength="7">
</asp:TextBox>

我能够获得最小数量但无法获得最大数量。仅限输入 7 位数字。

【问题讨论】:

  • 你的文本框上有一个 MaxLength="7" 吗?
  • @sh1rts 非常感谢您指出我。

标签: c# asp.net


【解决方案1】:

这是您的解决方案:-

 <asp:TextBox ID="txtphonenumber" runat="server"></asp:TextBox>
 <asp:RegularExpressionValidator Display = "Dynamic" ControlToValidate = "txtphonenumber" ID="revphone" ValidationExpression = "^[\s\S]{7,15}$" runat="server" ErrorMessage="Minimum 7 and Maximum 15 characters required."></asp:RegularExpressionValidator>

欲了解更多信息,请参阅下面的链接.....

https://www.aspsnippets.com/Articles/TextBox-Minimum-and-Maximum-Character-Length-Validation-using-ASPNet-RegularExpression-Validators.aspx

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-02
    • 1970-01-01
    • 1970-01-01
    • 2013-10-09
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    相关资源
    最近更新 更多