Search code examples
angulartypescriptangular2-formsangular2-directives

How to restrict Input box with 2 decimal places in Angular 2/4/5


I had a scenario that I should restrict a input box with 2 decimal places in Angular 2/4/5. Should I write a directive for this?

example: 12.25, 14524.21, 12547896324.01

We should not allow user to enter extra keystroke after completion of two decimal values


Solution

  • try this regex

    /^\d*(?:[.,]\d{1,2})?$/