Dayana Benny Dayana Benny - 1 year ago 74
PHP Question

Show "invalid value" in html form (min=0 max=2) when decimal value given

I want to submit decimal values through html input box. But showing
input error as "invalid input" when giving value 1.5 where min=0 and

html code is given below:

<input type="number" required value="<?php echo $someDecimalvalue; ?>" min="0" max="3" >

Answer Source

There is an attribute step for this purpose:

Works with the min and max attributes to limit the increments at which a numeric or date-time value can be set. It can be the string any or a positive floating point number. If this attribute is not set to any, the control accepts only values at multiples of the step value greater than the minimum.

So if you want to allow one decimal place, add step="0.1" to your input tag.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download