Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (20.3k points)

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

1 Answer

0 votes
by (40.7k points)

You can just add the max attribute this will specify the highest possible number that you can insert

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

But, 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 code will still not stop you from manually entering a value outside of the specified range. 

Instead you can display a popup telling it to enter a value within this range upon submitting the form as shown in this screenshot:

Browse Categories

...