When inputting special characters into the field used for storing the alphanumeric serial number, they are accepted. I need to prevent special characters from being entered in the input field.
<ion-input [(ngModel)]="serial_number" (ngModelChange)="validation($event)" #serialno id="serialno" class="cac-input"></ion-input>
validation(event) {
const inputElement = document.getElementById('serialno') as HTMLInputElement;
const pattern = /^[a-zA-Z0-9]*$/;
console.log(event)
console.log(pattern.test(event))
let c = event.replace(/[^a-zA-Z0-9 ]/g, '');
inputElement.value = '';
inputElement.value = c;
console.log(c)
this.serial_number = c;
}
In the past, I used regex to remove the special characters, but even after removal, the value still shows up in the input field.
Using the (keypress) event in the browser works fine, however, it does not work on Android.