I have an input field. I want to restrict user from entering special characters. Only alphanumeric values are allowed. I have implemented below code but when any special characters is pressed it is visible in input field.
component.html
<input type="text" placeholder="Name" [formControl]="myName" (ngModelChange)="value($event)">
component.ts
value(text: any){
text = text.replace(/[^a-zA-Z0-9-]/g, '');
}