<input class="input" pInputText [disabled]="disabled" [(ngModel)]="data.input.value"
(change)="inputOnChanges()" (keypress)="keyPress($event)" >
.ts file
const pattern = /^[+]?([0-9]+(?:[\.][0-9]*)?|\.[0-9]+)$/;
console.log('event is::',event);
const inputChar = String.fromCharCode(event.charCode);
if (!pattern.test(inputChar)) {
// invalid character, prevent input
event.preventDefault();
}
I am using above regex. Also, it says charCode is deprecated. Also, keyboard shortcuts should be allowed e.g. copy, paste, arrow keys. Also, user should not be allowed to copy, paste any special characters.