...

View Full Version : Form GET variable type



shanstafari
10-31-2006, 08: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.

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


<?php

$number = $_POST['inputBox'];

if(is_numeric($number))
{
Code you want to run if number was inputted
}
else
{
Code you want to run if number was NOT inputted
}

?>

Is that what you're after?

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

GJay
11-02-2006, 05:18 PM
[quote=php.net]
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.
[/php]
http://php.net/is-numeric

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

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum