I want to restrict certain string like TEST,DUMMY to be removed from text box entry, i did below code but not working
<mat-form-field class="example-full-width" style="width:1000%">
<input (input)="inputValidator($event)" matInput id="SiteId" formControlName="SiteId" placeholder="Enter Site Id" type="text" required />
</mat-form-field>
In .ts file
public inputValidator(event: any) {
console.log('event.target'+event.target.value);
// const pattern = /^[a-zA-Z0-9]*$/;
const pattern =/^(TEST|DUMMY)$/ ;
//let inputChar = String.fromCharCode(event.charCode)
if (!pattern.test(event.target.value)) {
event.target.value = event.target.value.replace(/[^(TEST|DUMMY)$]/g, "");
// invalid character, prevent input
}
}