In short:
If you attach an observer method like keypress, what is returned to the function is a character code. This code can be many things, but in your case, it is a number. Even when an actual number key is pressed on the keyboard, a different number is returned. So, your function has the if statement to condition the error/warning message when any character code not corresponding to a number is returned.