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.

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.)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.