I want to validate a Textbox using Angular 5 and it should not accept any characters other than numbers.
I have written following code, Its Working on Pc Browser but its not working on Android Mobile Browsers.
Below is my code ,
- <mat-form-field fxFlex="20" class="RightInput">
- <input matInput name="Indication1PatientNo" formControlName="Indication1PatientNo" placeholder="Patient No." (keypress)="_OnlyNumeriCkeyPress($event)">
- </mat-form-field>
- _OnlyNumeriCkeyPress(event: any) {
- const pattern = /[0-9\+\-\ ]/;
- let inputChar = String.fromCharCode(event.charCode);
-
- if (!pattern.test(inputChar)) {
-
- event.preventDefault();
- }
- }