This project adds a new directive called NgxNumbersOnly
it assures an HTML Input element will
only recieve numbers.
it can be defined to allow negative numbers or disallow them as well as decimal point numbers.
This project was generated with Angular CLI version 11.2.6.
Run npm i ngx-numbers-only-directive
.
In your appModule Import NgxNumbersOnlyDirectiveModule:
import { NgxNumbersOnlyDirectiveModule }
and add it to your imports array:
imports: [NgxNumbersOnlyDirectiveModule]
Add the directive to an input element. example:<input NgxNumbersOnly>
To allow Negative numbers:<input NgxNumbersOnly [allowSign]=true>
To allow decimals:<input NgxNumbersOnly [allowDecimals]=true [allowSign]=true>
If you enjoyed this code consider donating using paypal:Donations
The base for this directive was a StackOverflow answer by Elvis Fernandez.