0

I need to restrict special character in html input box with Angular 7. Similarly I have some other requirement like to enter only number, letter etc.

Am new to Angular, any help will be appreciated.

I tried with some below code:

<input type="text" maxlength="45" class="form-control" id="hno" [(ngModel)]="Address.number" pattern="^[^`~!@#$%\^&*()_+={}|[\]\\:';"<>?,./]*$">
user11335918
  • 81
  • 1
  • 2

1 Answers1

0

Your pattern attribute should look like this:

pattern="[^`~!@#$%\^&*()_+={}|[\]\\:';<>?,./\x22]*"

Firstly, you should NOT use ^ and $ because you match every single character with this pattern.

Secondly, there is a problem with the " character. So for now I just removed it from the class, will look more into it.

UPD: Found a solution for a quote character here. \x22 works as " character.

Here is a working example: https://jsfiddle.net/qy5m07uh/

Ildar Akhmetov
  • 1,331
  • 13
  • 22