ion-input only delimited numbers ionic3

0

Good morning, I'm new to ionic, I did a search for the site but I did not find an answer to my question. See if you can help me:

I want to delimit a data entry with numbers only.

The maxlength attribute does not work in type type only in type tel. However, in tel type you can insert letters and special characters like # and *.

In addition, in the type number you can enter a point.

I would like only numbers, with a maximum number of 5 digits. Would anyone help me?

    
asked by anonymous 05.07.2018 / 15:56

2 answers

0

I have. Here is my solution: In the .ts file

formatar()
    {
       var login = this.login.rg;

       if(this.login.rg != undefined){
        login = login.replace(/\D/g, '');
        this.login.rg = login;
        console.log(this.login.rg);
       }

    }

In the .html file:

<ion-input type="tel"  (keyup)="formatar()" maxlength="5" size="4" clearInput placeholder="Digite seu RG (Somente números)" pattern="[0-9]" [(ngModel)]="login.rg" name="rg"></ion-input>
    
06.07.2018 / 14:29
1

Do so on your ion-input:

<ion-input type="tel" pattern="[0-9]*"></ion-input>

It works on:

  • iOS 9/10 +
  • Android 5 +
05.07.2018 / 18:20