I'm working on an Angular app, and I have an input that shouldn't accept any character except for English letters, numbers and some symbols.
I prevent the input from accepting arabic letters by creating a directive and creating a regex to check the user input:
if !myRegex.test(event.key)
event.preventDefault()
And it works, but when insert this letter "لا" which is a compound letter, the check catches it, but the input is filled with this letter "ا".
Any suggestions solve this problem?
By using directive, the input is linked to property ngModel, so I can't add a validator to it like with a form control.
Approach
Approach Instead of using the ngModel Directive, you can create your own Directive with Input and Output which works same as the ngModel Directive. There you can place your Regex and no char you dont want are into your variable in your ts file.