Jump to content

Recommended Posts

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.