I am adding validation to some input fields in my reactive class-driven form. Here is an example of some of my input fields:
.html
<input matInput formControlName="{{ field?.controlName }}" maxLength="{{ field?.maxLength }}" placeholder="{{ field?.label }}">
<span matSuffix class="input-suffix">Required</span>
In the browser
I would like to know how to add a feature that prevents any special characters from being entered.
NOTE: I am already using a custom validator function that will raise a small error message if any characters match a regex.
However, I want it to prevent resticted characters from even appearing. So if a user typed '%' or '&' nothing would happen. Also, I want to allow some characters, like apostrophes or hypens.