1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

keypress events not working on mobile chrome browser

Discussão em 'Angular' iniciado por franco, Setembro 10, 2024.

  1. franco

    franco Guest

    I work with angular 7.

    I have this code which is working in desktop with chrome browser. with this code I can enter only numbers and not more than 4 number.

    html code :

    <div class="col-12 col-md-6">
    <div class="form__group btm">
    <label class="form__label">


    numidentity :

    </label>

    <input
    class="form__input validation-field"
    [(ngModel)]="this.numidentity"
    (keypress)="keyPressNumbersIdentity($event)"
    placeholder=""
    type="text" >


    </div>
    </div>



    typescript code :

    keyPressNumbersIdentity(event) {
    var charCode = (event.which) ? event.which : event.keyCode;

    // Only Numbers 0-9
    if ((charCode < 48 || charCode > 57)) {
    event.preventDefault();
    return false;
    } else {

    if (event.target.value.length >4) {
    event.preventDefault();
    return false;
    }
    else
    {
    return true;
    }


    }
    }


    but when I test the same html page in mobile android chrome browser the (keypress) events not working meaning I can enter characters not only number and more then 4 number.

    Continue reading...

Compartilhe esta Página