Ngx-mask: Configure if negative number is allowed in separator mask

Created on 7 Jan 2020  路  2Comments  路  Source: JsDaddy/ngx-mask

It would be nice to be able to config if a negative number is allowed in separator mask. For most of my currency inputs I don't want the user to be able to type negative numbers.

P1 enhancement help wanted

Most helpful comment

This is will be very nice.
Currently I couldn't find a simple way to block "-" character in inputs with the separator masks.
Even if the dropSpecialCharacters works, it would be good to prevent user typing.

Edit (01/16/2020)
The way I found to remove "-" from is through (keypress) event, where you have a check if the character pressed is "-".

<input formControlName="currency" mask="separator.2" name="currency" separatorLimit="100" type="text" dropSpecialCharacters="true" (keypress)="isPositive($event)" />

isPositive(event: any) { return event.key === '-' ? false : true; }

It works good. Obviously not as good as having the option to configure if negative numbers are allowed. :)

All 2 comments

This is will be very nice.
Currently I couldn't find a simple way to block "-" character in inputs with the separator masks.
Even if the dropSpecialCharacters works, it would be good to prevent user typing.

Edit (01/16/2020)
The way I found to remove "-" from is through (keypress) event, where you have a check if the character pressed is "-".

<input formControlName="currency" mask="separator.2" name="currency" separatorLimit="100" type="text" dropSpecialCharacters="true" (keypress)="isPositive($event)" />

isPositive(event: any) { return event.key === '-' ? false : true; }

It works good. Obviously not as good as having the option to configure if negative numbers are allowed. :)

Was this page helpful?
0 / 5 - 0 ratings