Jump to content

Making sure a number is entered in a field


squaringkarma

Recommended Posts

How would you validate a form to make sure a user entered in a number for a specific field? I'm blanking on that right now. I'm working on a site where there are 3 different forms depending on what a user inputs for their age. If the user does not enter their age, I want the initial form to reappear with an error of "Please enter your age." Right now, the initial form only appears when the trimmed string length for the field is 0.

Link to comment
Share on other sites

Hm thanks. mgallforever, when I try with is_int, I always get false. I presume this is because it's form input and it's reading it as a string. I guess my next question would be how do you convert a string into a number? (Though the ctype_digit is accepting strings as input, so maybe the answer to my question isn't necessary.)

Link to comment
Share on other sites

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.