Checking if a letter was type into a form

For discussions about game development that does not fit in any of the other topics.
Post Reply
Baseball435
Posts: 548
Joined: Sun May 30, 2010 3:49 am

Checking if a letter was type into a form

Post 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!
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Checking if a letter was type into a form

Post 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";
?> 
Image

Image
User avatar
rockinliam
Posts: 466
Joined: Sun Jun 07, 2009 11:26 am

Re: Checking if a letter was type into a form

Post 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...
Skillset: C/C++, OpenGL, C#, Lua, PHP, MySql, Web Dev etc.
Website: https://liam-griffiths.co.uk/
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Checking if a letter was type into a form

Post 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
Image

Image
Baseball435
Posts: 548
Joined: Sun May 30, 2010 3:49 am

Re: Checking if a letter was type into a form

Post by Baseball435 »

Thanks for all the answers guys :)
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

Re: Checking if a letter was type into a form

Post by Callan S. »

And thanks from me as well, cause that seems a good one to try and remember! :)
Post Reply

Return to “General Development”