I am building a form using angularjs, and I have got a amount field in it.
I want to validate and format the amount so, that invalid amount is restricted and only valid amount should be entered, rest all should be discarded. Valid amount are:
1.23
0.99
so, basically, 1 digit followed by 2 decimal points.
I am confused to use between filters or directives, as I have never used any of them. I would appreciate, If anyone has done similar thing in past and if you can share with me or if you can give me solution.
I have used ng-pattern like this ng-pattern="/^[0-9]*\.[0-9][0-9]$/
but doesn't work for me.
I am using AngularJS 1.4 latest version.
EDIT - MY DODE
<input type="number"
name="globalNetPrice"
value="{{netprice.globalNetPrice}}"
ng-model="netprice.globalNetPrice"
class="form-control"
required
ng-minlength="0.01"
ng-maxlength="999"
ng-pattern="/^[0-9]+.[0-9][0-9]$/"
>
<p ng-show="netpriceForm.globalNetPrice.$invalid && !netpriceForm.globalNetPrice.$pristine">
<small class="error" ng-show="netpriceForm.globalNetPrice.$error.required">Net Price is required.</small>
<small class="error" ng-show="netpriceForm.globalNetPrice.$error.number">That is not a Net Price. Please input a valid Net Price.</small>
<small class="error" ng-show="netpriceForm.globalNetPrice.$error.pattern">That is not a valid Net Price. Pattern not valid.</small>
</p>
You also use directive for this :-