Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Float number validation in angular for min and max fields

I need for min and max fields validation on float number, that is 1.59 is allowed but anything higher than is not allowed like 1.60 also 1.00 should be the minimum value. Here i am used angular form for submit the data.

like image 747
Jenson Raby Avatar asked Sep 10 '26 14:09

Jenson Raby


2 Answers

Use min and max directives for this as follows,

<div>
    <form name="myForm">
        <input type="number" min="1" max="1.59" ng-model="enteredNumber" name="numberName" />
    </form>

    Validity of the entered number = {{ myForm.numberName.$valid }}
</div>

You can check whether the number entered is valid or not by using $valid

like image 144
Chinni Avatar answered Sep 14 '26 05:09

Chinni


Try with this pattren

ng-pattern="/^[0-9]+(\.[0-9]{1,2})?$/"

<input type="number" name="myDecimal" placeholder="Decimal" ng-model="myDecimal" ng-pattern="/^[0-9]+(\.[0-9]{1,2})?$/" step="0.01" />
<span>Is a valid decimal? {{myForm.myDecimal.$valid}}</span>
like image 41
zeeshan Qurban Avatar answered Sep 14 '26 06:09

zeeshan Qurban