'Key event filtering for numbers, letters or other groups

Angular4 docs shows ( Key event filtering (with key.enter) ) how to catch keyboard keystrokes events easier - (keyup.enter)="foo()" or keyup.w or keyup.space etc.

What I need is to fire event only if letters being pressed.

One way I can think of is:

<input id="textFilter" (keyup)=“foo($event)”>

  foo(e){
    var allowedKeys = [‘KeyQ’, ‘KeyW’, ‘KeyE’, and the rest of the alphabet...]
    if (allowedKeys.indexOf(e.code) != -1 ) {
      return true;
    }
  }

But I would expect such pseudo-events already build-in in Angular. For ex. for letters, like - (keyup.letters)="foo()" and for numbers, like -(keyup.numbers)="foo()". Are there any? And is that solution above is preferable for filtering keyboard keystrokes by groups?

docs

I appreciate any help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source