[英]How to set limit of max length to TextBox?
I have set limit maxlength="9" for TextBox, code is below: 我为TextBox设置了限制maxlength =“9”,代码如下:
<asp:TextBox ID="txtEIN" runat="server" CssClass="search-box" maxlength="9" type="number" pattern="[0-9]*" placeholder="EIN without dash"></asp:TextBox>
But the problem is we can enter more than 9 number, but I need to set max limit to 9. 但问题是我们可以输入9个以上的数字,但我需要将最大限制设置为9。
The MaxLength
property will not work when using a "number" input (ie type="number"
). 使用“数字”输入(即
type="number"
)时, MaxLength
属性将不起作用。 You could consider setting the max
and min
attributes to handle the range : 您可以考虑设置
max
和min
属性来处理范围:
<asp:TextBox ... type="number" min="1" max="999999999"></asp:TextBox>
For a complete solution, you would probably want to rely on some client-side code to explicitly restrict what can/cannot be entered into the element or consider using a third-party component that would handle this type of behavior for you. 对于完整的解决方案,您可能希望依赖某些客户端代码来明确限制可以/不能输入到元素中的内容,或者考虑使用可以为您处理此类行为的第三方组件。
您可以设置TextBox的MaxLength属性
textBox1.MaxLength = 9;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.