Skip to content
Advertisement

How to force input to only allow Alpha Letters?

using jQuery here, however unable to prevent numbers from being typed into the input field

http://codepen.io/leongaban/pen/owbjg

Input

JavaScript

jQuery

JavaScript

I’ve seen plenty of examples here on how to restrict to only Numbers, and I’m using the correct key codes for a-z and A-Z. Do you see what I’m doing wrong?

Advertisement

Answer

The property event.key gave me an undefined value. Instead, I used event.keyCode:

JavaScript

Note that the value of 8 is for the backspace key.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement