Reputation: 23
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.
Upvotes: 1
Views: 10278
Reputation: 419
you can set MaxLength Property of TextBox
textBox1.MaxLength = 9;
Upvotes: 2
Reputation: 76607
The MaxLength
property will not work when using a "number" input (i.e. 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.
Upvotes: 2