angular input value just below the input code example
Example 1: preventing +,-,e from input ts
<input(keyup)="_keyUp($event)">
Example 2: preventing letters from being placed in an input ts
validateNumber(event) {
const keyCode = event.keyCode;
const excludedKeys = [8, 37, 39, 46];
if (!((keyCode >= 48 && keyCode <= 57) ||
(keyCode >= 96 && keyCode <= 105) ||
(excludedKeys.includes(keyCode)))) {
event.preventDefault();
}
}
Example 3: preventing +,-,e from input ts
_keyUp(event: any) {
const pattern = /[0-9\+\-\ ]/;
let inputChar = String.fromCharCode(event.key);
if (!pattern.test(inputChar)) {
event.preventDefault();
}
}