Page 1 of 1

Verification in Forms

Posted: Fri Mar 14, 2003 2:41 am
by phpRoundX
Hi,
I've made a form for user-Adds. I want to verify, that one textfield is checked for "not empty" and one other checked for- it has to be an int oder double.

e.g.
if (empty($_POST[C]))
{
echo "here's the output, when if ist TRUE<br>";
}


I've done all with POST and everything ist fine with empty, but how can a form-textfield be checked for, that the Value has to be a Number?
Can I make this wir is_int oder is_double somewhere in the IF-Block. Some like:
if ( (empty($_POST[C])) && (is_integer($_POST[A])) )
.... bla

?????

Jan

Posted: Fri Mar 14, 2003 2:46 am
by twigletmac
You can do this:

Code: Select all

if (empty($_POST['C']) && is_numeric($_POST['A'])) {
    // blah
}
Don't forget the quotes around the array elements ($_POST['C'] instead of $_POST[C]) for why see this page:
http://www.php.net/manual/en/language.t ... rray.donts

Also you would use is_numeric() instead of is_integer() because:
PHP Manual - is_int() wrote:Note: To test if a variable is a number or a numeric string (such as form input, which is always a string), you must use is_numeric().
Mac

Posted: Fri Mar 14, 2003 2:49 am
by Tubbietoeter
Hi,


try preg_match() here:


if ( (empty($_POST[C])) && (preg_match("/[0-9]+/",$_POST[A])) )

you're Legends :)

Posted: Fri Mar 14, 2003 3:00 am
by phpRoundX
thx for that fast help.

Jan