I have a need to validate text entered into a textbox
using JavaScript before it's sent off to a third party to be acted upon.
To do this, I'm using the browserEvent.keyCode
parameter to get the keycode
sent to the browser on the key-up event, then validating the code to say whether it's allowed in the textbox
or not.
This works fine across all devices I've tested, apart from Chrome on the HTC One X.
I've found annoying differences between various Android and iOS devices, but they all return something that I can work with. The HTC One X, however, returns 0
with every key press apart from the Backspace and Enter keys, which return 8
and 13
respectively.
I've tried event.keyCode
, event.charCode
and event.which
as well as browserEvent.keyCode
, browserEvent.charCode
and browserEvent.which
codes, and everything is returned as a 0
.
Basically, I'm stuck. Does anyone have any idea
keycode
is always returned as 0
on this device, and keycode
?Although it doesn't answer the immediate question, I used some of the ideas Lukas Knuth gave me to solve it.
The process is now that a keycode of 0 is caught and handed to a function that runs the contents of the input box through some Regex validation. If the validation fails, then the last character is removed from the input box.
I apologise if anyone comes to this question seeking a solution for the HTC One X passing through 0 as the keycode, after a couple of days of research and experimentation, I couldn't find a solution, so I worked around the problem instead.