Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to prevent input type="number" getting negative values?

I want to get only positive values, is there any way to prevent it using only html
Please don't suggest validation method

Screenshot of input control

like image 457
Tural Ali Avatar asked Sep 10 '11 13:09

Tural Ali


People also ask

How do you prevent negative values in input type text?

You can could use something like <input type="number" name="test" min=0 save="" oninput="validity. valid ? this. save = value : value = this.

How do you make an input type number only positive?

As we know, the <input type="number"> specifies a field for entering a number. If you want to restrict the <input> field to only positive numbers, you can use the min attribute.


1 Answers

Use the min attribute like this:

<input type="number" min="0"> 
like image 141
Abraham Avatar answered Sep 20 '22 03:09

Abraham