0

How do I make my input field only accept numbers (don't allow ANY letters to be inputted) and also hide the inputted values? It is taking a sensitive number. This also needs to keep the max and minlength validation at 4.

Here is what is not working:

<input matInput type="password" pattern="[0-9]*"  minlength="4" maxlength="4" placeholder="Last Four of SSN" formControlName="ssn" required>
John Man
  • 31
  • 5
  • Does this answer your question? [Angular2 - Input Field To Accept Only Numbers](https://stackoverflow.com/questions/41465542/angular2-input-field-to-accept-only-numbers) – Edric Aug 07 '20 at 06:30
  • No, need to hide inputted values, accept only numbers, and have a min and max length set to 4. – John Man Aug 07 '20 at 06:36

2 Answers2

1

Try this regex for your pattern

[pattern]="'^[0-9]{4}$'"
Kirubel
  • 1,461
  • 1
  • 14
  • 33
0

Do not forget to set also the angular validator for this form field (own validator or pattern validator)