angular prevent character input code example
Example 1: preventing +,-,e from input ts
<input(keyup)="_keyUp($event)">
Example 2: preventing +,-,e from input ts
_keyUp(event: any) {
const pattern = /[0-9\+\-\ ]/;
let inputChar = String.fromCharCode(event.key);
if (!pattern.test(inputChar)) {
// invalid character, prevent input
event.preventDefault();
}
}