How to make type="number" to positive numbers only

Arian Faurtosh picture Arian Faurtosh · Oct 7, 2013 · Viewed 359.5k times · Source

currently I have the following code

<input type="number" />

it comes out to something like this

enter image description here

The little selector things on the right allow the number to go into negative. How do I prevent that?

I am having doubts about using type="number", it is causing more problems than it is solving, I am going to sanity check it anyways, so should I just go back to using type="text"?

Answer

Quentin picture Quentin · Oct 7, 2013

Add a min attribute

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