简体   繁体   中英

How to set limit of max length to TextBox?

I have set limit maxlength="9" for TextBox, code is below:

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

The MaxLength property will not work when using a "number" input (ie type="number" ). You could consider setting the max and min attributes to handle the range :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM