Sajjan Sarkar
Sajjan Sarkar

Reputation: 4198

ngx-mask - Simple Decimal Mask Not working

I would like a textbox that allows only 2 decimals. I am using https://github.com/JsDaddy/ngx-mask/ to achieve this.

This example ( using Angular 8 and an older mask version ) works , but looks like the newer version doesnt!

This is my html:

<input type="text" mask="99999999999999.00">

Error repro :

https://stackblitz.com/edit/angular-ivy-mask-9g3gqs?file=src%2Fapp%2Fapp.component.html

enter image description here

NOTE: I have logged a defect in the repo, but was hoping someone in SO can also guide me in case Im missing something simple.

Upvotes: 1

Views: 25757

Answers (3)

Mina Djuric
Mina Djuric

Reputation: 603

None of this examples work. What worked for me is adding leadZero property with mask separator

<input type="text" mask="separator.2" [leadZero]="true" />

Upvotes: 1

Dalton Smith
Dalton Smith

Reputation: 11

If you don't want to limit the number of numbers before the decimal point, you can use this mask: 0*.00.

See other examples here

Upvotes: 1

Ashot Aleqsanyan
Ashot Aleqsanyan

Reputation: 4453

it is a bug coming from the package you can open the issue in GitHub,

But for now you can use several workarounds.

  1. Use early versions of the package for example 8.2.x. The command for installing the old version of this package npm i [email protected]

  2. or use mask by this way

<input type="text"  mask="separator.2" thousandSeparator="" separatorLimit="99999999999999">

Here is the stackblitz example with the second solution https://stackblitz.com/edit/angular-ivy-mask-juzncf?file=src/app/app.component.html

Upvotes: 5

Related Questions