View Full Version : Form GET variable type

10-31-2006, 09:52 PM
Is there a way to make sure that the value entered into a text input is an integer (without using Javascript or some such nonsense)? I have a text input that should be only for integers, but even when you type a number in, PHP recognizes the passed variable as a string.

11-01-2006, 01:15 AM
Try this


$number = $_POST['inputBox'];

Code you want to run if number was inputted
Code you want to run if number was NOT inputted


Is that what you're after?

11-02-2006, 05:33 PM
So the is_numeric function will tell me if the value of a string variable is actually a number?

11-02-2006, 06:18 PM
Finds whether the given variable is numeric. Numeric strings consist of optional sign, any number of digits, optional decimal part and optional exponential part. Thus +0123.45e6 is a valid numeric value. Hexadecimal notation (0xFF) is allowed too but only without sign, decimal and exponential part.

might also want to take a look at http://php.net/filter

11-02-2006, 06:45 PM
Hmm... seems like I could make that work for me. Thanks guys.