Angular 2 - Only Allow 2 Decimal Places For Amounts

时间:2016-10-20 13:23:39

标签: angular angular2-directives angular2-forms

Im new to Angular 2 and i wa wondering if there is a way to restict and amount field to only allow 2 decimal places.

I have tried the below as i have read a few places it should work but i cant seem get it to.

<input id="amountfield" ng-model="vm.transferdetails.Amount" ng-model-options="{ updateOn:'blur' }" ng-pattern="/^[0-9]+(\.[0-9]{1,2})?$/" step="0.01">

If i have to use a directive, what do i need and also can it be formatted with , (commas) for thousands (e.g. 100,000,000.00) when you tab out the field. Only really intrested in this though if i have to use a directive

1 个答案:

答案 0 :(得分:1)

以下是我认为可以帮助您的输入。在另一篇文章中回答:

Number pipes in Angular2 not working as I would expect