random1 Posted April 28, 2011 Share Posted April 28, 2011 I have a form field that I'm currently allowing only positive numbers to be entered in. I'm currently using onkeypress on the input field: <input name="card_security_code" type="text" maxlength="4" size="4" onkeypress="return onlyNumbers(event);" /> It's currently working although I'm concerned about using onkeypress, is it reliable and does this fire when using things like ipod and mobile devices? I've heard that using onblur is not recommended for this and I've tried using onchange but that does not work. Any suggestions on what I should use for this kind of field validation? Link to comment https://forums.phpfreaks.com/topic/234936-onkeypress-for-input-field/ Share on other sites More sharing options...
doddsey_65 Posted April 28, 2011 Share Posted April 28, 2011 not sure about mobile devices and ipods. Some of these have JS turned off by default. Do you have a fallback option for this case? I would personally use onBlur to check the value and then use a php script to check when the form is being submitted. That way people with JS turned off will still recieve an error when entering the wrong values. Link to comment https://forums.phpfreaks.com/topic/234936-onkeypress-for-input-field/#findComment-1207417 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.