Prasad Prasad -5 years ago 439
HTML Question

How to add maxlength for HTML5 input type="number" element?

For input type="number" element, maxlength is not working. How can I restrict the maxlength for that number element?

Answer Source

And you can add a max attribute that will specify the highest possible number that you may insert

<input type="number" max="999" />

if you add both a max and a min value you can specify the range of allowed values:

<input type="number" min="1" max="999" />

The above will still not stop a user from manually entering a value outside of the specified range. Instead he will be displayed a popup telling him to enter a value within this range upon submitting the form as shown in this screenshot:

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download