How to check if keyup is a character key with jQuery?

Sometimes, we want to check if keyup is a character key with jQuery.

In this article, we’ll look at how to check if keyup is a character key with jQuery.

How to check if keyup is a character key with jQuery?

To check if keyup is a character key with jQuery, we can check the keypress event.

For instance, we write:

<input>

to add an input.

Then we write:

$("input").keypress((e) => {
  if (e.which !== 0) {
    console.log("Character was typed", String.fromCharCode(e.which));
  }
});

to select the input with $.

Then we call keypress with the event handler that checks the character code of the key that’s pressed with e.which.

If it’s not 0, then we pressed a character key.

And we get the character code with String.fromCharCode with the character code from e.which.

Conclusion

To check if keyup is a character key with jQuery, we can check the keypress event.