简体   繁体   中英

Angular Input Type PASSWORD and NUMBER

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>

Try this regex for your pattern

[pattern]="'^[0-9]{4}$'"

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM