preventing letters from being placed in an input ts

Solutions on MaxInterview for preventing letters from being placed in an input ts by the best coders in the world

showing results for - "preventing letters from being placed in an input ts"
Simone
19 Nov 2016
1  validateNumber(event) {
2    const keyCode = event.keyCode;
3
4    const excludedKeys = [8, 37, 39, 46];
5
6    if (!((keyCode >= 48 && keyCode <= 57) ||
7      (keyCode >= 96 && keyCode <= 105) ||
8      (excludedKeys.includes(keyCode)))) {
9      event.preventDefault();
10    }
11  }
12
Greta
04 Apr 2019
1<input type="password" placeholder="Enter Mobile no" formControlName="mobile_no" (keydown)="validateNumber($event)">
2