Keydown event not working in Android


#1

I write a function using KeyboardEvent to let a input only allow number, ‘-’ key and BackSpace key. When I test in ionic serve or ios, it worked. But when I test in Android its not working, input field will allow all the character inputed.
When I use console.log(event), it always returns the key=“Unidentified”, keyCode = 229.

Environment: Ionic 3, Node v6.11, npm 3.10, Android 5.1.1
I dont know how to fix this. I’m a newbie in Ionic, anyone give me advise, plz!

.ts file

import {Component} from '@angular/core';
import {NavController} from 'ionic-angular';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  constructor(public navCtrl: NavController) {

  }

  isValidNumber(event) {
    //console.log(event);
    return /\d|-|Backspace/.test(event.key);

  }
}

.html file

<ion-header>
  <ion-navbar>
    <ion-title>Home</ion-title>
  </ion-navbar>
</ion-header>
<ion-content>
  <ion-item>
      <ion-input  type="text" (keydown)="isValidNumber($event)"></ion-input>
  </ion-item> 
</ion-content>

#2

same here but for me its 0 not 229


#3

…Any solution?