Page 1 of 1

Checking if a letter was type into a form

Posted: Wed Nov 17, 2010 12:00 am
by Baseball435
Hey guys, well im working on a house script for my game and im having it so that you can store money inside your house. I have a form and everything all setup but i dont know how to check on the action page if a letter was type into the form when i only want numbers. If you guys could help me that would be great! Thanks Guys!

Re: Checking if a letter was type into a form

Posted: Wed Nov 17, 2010 12:15 am
by SpiritWebb
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().

Code: Select all

<?
if(is_numeric($variable))
echo "Pass test";
else
echo "Please use only numbers";
?> 

Re: Checking if a letter was type into a form

Posted: Wed Nov 17, 2010 12:24 am
by rockinliam
Yey time for one of my favourite functions :P

Code: Select all

<?php
	if (is_numeric($coinsADD)) {
		echo "You have added $coinsADD coins to your pile...";
	} else {
		echo "TYPE NUMBERS YOU STUPID PERSON";
	}
?>
Edit: Damn lol spirit posted whilst i was reading an email...

Re: Checking if a letter was type into a form

Posted: Wed Nov 17, 2010 12:35 am
by SpiritWebb
rockinliam wrote:Yey time for one of my favourite functions :P

Code: Select all

<?php
	if (is_numeric($coinsADD)) {
		echo "You have added $coinsADD coins to your pile...";
	} else {
		echo "TYPE NUMBERS YOU STUPID PERSON";
	}
?>
Edit: Damn lol spirit posted whilst i was reading an email...

Muahahahahaha

Re: Checking if a letter was type into a form

Posted: Wed Nov 17, 2010 12:50 am
by Baseball435
Thanks for all the answers guys :)

Re: Checking if a letter was type into a form

Posted: Wed Nov 17, 2010 2:59 am
by Callan S.
And thanks from me as well, cause that seems a good one to try and remember! :)