I have this which works perfectly on desktop browsers. It checks when the user presses a key in a zipcode text input field:
zip_field.addEventListener(
'keydown',
function(evt){check_zip({evt:evt, zip_field: zip_field, submit_button: submit_button})},
false
)
The check_zip function has this at the bottom to cancel the keypress if the user types a letter, etc.:
if(prevent_key)
{
evt.preventDefault()
evt.stopPropagation()
return false;
}
On mobile browsers, the if statement is processed just like on the desktop browsers, but it still allows the character to go through. However, if I put breakpoints in and step through the code it works correctly!
I tested in Chrome and Firefox on Android and it happened on both. Is there something else I need to do on mobile to prevent/cancel the key and prevent it from appearing in the input box?
Update: I was able to test on iPhone and it is working correctly on there. So it's only broken on Android (FF, Chrome, and Samsung browser are all failing).