I am using an functionality in which when I start typing in an Input box It will add the commas to the no and which is working fine but my issue is its not allowing decimals so how to allow decimals also with commas ?
Below code I am using to achieve commas thing.
<input type="text" matInput [(ngModel)]="budget" placeholder="budget" autocomplete="off" (keydown)="numberCheck($event)" (keyup)="CommaFormatted($event)">
CommaFormatted(event) {
if(event.which >= 37 && event.which <= 40) return;
if (event.target.value) {
event.target.value = event.target.value.replace(/\D/g, "")
.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
}
numberCheck (args) {
if (args.key === 'e' || args.key === '+' || args.key === '-') {
return false;
} else {
return true;
}
}
So how to allow decimals also in this input box. Any help will be appreciated.
Thanks in advance.