I am trying to disable all other characters from being entered in text input.
Since to get the $ you have to press the shift-key and the 4-key. I am not sure how you would get the keyCode for somthing like this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Key codes relate only to keys.
$is a character, achieved through two keys, Shift and 4. There is no key code explicitly for$when usingonkeydownEdit: It was pointed out by Edward that
onkeypressuses key combinations, and does have keycode’s for combinations. Learn something new every day 🙂Here’s some code, edited from the
onkeydownexample provided by the MDN, to detect keypress keycodes.Here’s the fiddle updated to be Firefox-friendly, using help from this S.O. post. The JQuery solution works too, if you swing that way.