Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

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"?

like image 214
Arian Faurtosh Avatar asked Oct 07 '13 19:10

Arian Faurtosh


2 Answers

Add a min attribute

<input type="number" min="0">
like image 134
Quentin Avatar answered Oct 19 '22 13:10

Quentin


I have found another solution to prevent negative number.

<input type="number" name="test_name" min="0" oninput="validity.valid||(value='');"> 
like image 31
Kushal Avatar answered Oct 19 '22 15:10

Kushal