javascript - Android KeyUp, KeyDown, and KeyPress events not working with Angular2 -


i'm running issue when run either

<input type="text" (keydown)="testkeycodes($event)"/>  <!-- or -->  <input type="text" (keyup)="testkeycodes($event)"/>

i keycode of 229 in android chrome browsers, know has been mentioned several times on stack overflow, , i've seen recommendation use

<input type="text" (keypress)="testkeycodes($event)"/>

instead. problem is, keypress event not fired android phones. has found solution this?

my end goal prevent users on android browsers entering special characters alphanumeric inputs.

below regex i'd check against.

//tried  testkeycodes(event) {      if (!/[a-za-z0-9 ]/.test(event.keycode) && event.keycode != '8') {          event.preventdefault();      }  }    //and  testkeycodes(event) {      if (!/[a-za-z0-9 ]/.test(string.fromcharcode(event.keycode)) && event.keycode != '8') {          event.preventdefault();      }  }

any assistance appreciated. i'm stuck.

i write directive listen input event custom validator, following:

.... @hostlistener('input',['$event'])      oninput($event){       let newvalue = this.el.nativeelement.value;       ...          let patternvalidation=newvalue.match(mypattern); //replace here regexp        if(patternvalidation){          //keep input       } else {          //exclude input          newvalue = patternvalidation;       }        this.model.control.setvalue(newvalue);   }    <input mydirective [(ngmodel)]="value" name="value" > 

this described may want make more detailed.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -