How to limit input type = number to only positive numbers

The easiest way to do this is to set the minimum value in html:

<input type="number" min="0">

If 0 is also not allowed, you can set min = "1" or any other number you need.

This will limit the number selector on the right side of the input, but does not add any extra checks in case the user entered a negative number manually!

To avoid this, you can add a small js check:

<input type="number" name="input_name" min="1" 


No comments yet, you can leave yours: