0

How to achieve an ion-input just numeric and password at the same time?

Try to use pattern an ng-pattern and nothing works.

Not ng-pattern="/^([0-9])?$/" and pattern="[0-9]*" neither.

This pattern let me introduce characters not numeric.

The console doesnt show any error.

<ion-input class="ion-form-input" type="password" formControlName="Pin" (keyup)="this.equalPin()">
</ion-input>

Thanks.

Kenzo_Gilead
  • 2,187
  • 9
  • 35
  • 60
  • 1
    "nothing works" is not terribly informative. Do you get errors in the console? Does it allow you to enter values that are not numeric? You say you've tried pattern, but there is no `pattern` attribute on the input shown here. – Heretic Monkey Jun 10 '20 at 11:42
  • 1
    So, `pattern` allows you to enter invalid values; it just marks the input as invalid on blur. There are a number of questions on Stack Overflow about only allowing numeric characters in an input field. [Angular2 - Input Field To Accept Only Numbers](https://stackoverflow.com/q/41465542/215552) has a number of answers, for instance. You could try applying them to `type="password"` and see if they work. – Heretic Monkey Jun 10 '20 at 12:01
  • There is a way, not the cleanest probably, but on `(keydown)`, you catch the value of the key and you choose to allow it if it's a number, otherwise you preventDefault – Yoann Picquenot Jun 10 '20 at 12:02
  • @HereticMonkeyNothing works, but thank you. – Kenzo_Gilead Jun 10 '20 at 14:01
  • @YoannPicquenot Thanks for relying, but I cant do it in this way – Kenzo_Gilead Jun 10 '20 at 14:02

0 Answers0