Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html5 number type to accept only positive integers

I am using an angular app, with an html5 number type input. I am trying to restrict the input to only accepts positive integers and not decimal, floating point numbers.

I tried using some patterns and step=1 min, max values but does not seem to work.

Please suggest.

EDIT:

This is how my form looks like. Sorry for the confusion if I may have cause.

<div class="row bottom-spaced-small">
        <div class="col-md-3">
            Number*
        </div>
        <div class="col-md-9">
            <input name="txtNumber" ng-disabled="somevalue" min="1" step="1" type="number" ng-required="true" ng-maxlength="50" ng-model="someNumber" class="form-control color-black" />
        </div>
        <div class="row" style="padding-left: 30px" ng-if="someForm.$submitted && !someForm.txtNumber.$valid">
            <span style="color: red">Number is mandatory and must be a non 0 positive number.</span>
        </div>
    </div>
like image 938
Immortal Avatar asked Oct 27 '25 10:10

Immortal


2 Answers

You can set the min attribute, although check for support;

<input type="number" min="0" step="1">
like image 135
Benjy1996 Avatar answered Oct 29 '25 23:10

Benjy1996


You can set the min attribute, although check for support;

<input type="number" min="0" step="1">
like image 37
Benjy1996 Avatar answered Oct 30 '25 01:10

Benjy1996



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!