Checking if a letter was type into a form
-
Baseball435
- Posts: 548
- Joined: Sun May 30, 2010 3:49 am
Checking if a letter was type into a form
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!
- SpiritWebb
- Posts: 3107
- Joined: Sun Jul 12, 2009 11:25 pm
Re: Checking if a letter was type into a form
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";
?>
- rockinliam
- Posts: 466
- Joined: Sun Jun 07, 2009 11:26 am
Re: Checking if a letter was type into a form
Yey time for one of my favourite functions
Edit: Damn lol spirit posted whilst i was reading an email...
Code: Select all
<?php
if (is_numeric($coinsADD)) {
echo "You have added $coinsADD coins to your pile...";
} else {
echo "TYPE NUMBERS YOU STUPID PERSON";
}
?>
Skillset: C/C++, OpenGL, C#, Lua, PHP, MySql, Web Dev etc.
Website: https://liam-griffiths.co.uk/
Website: https://liam-griffiths.co.uk/
- SpiritWebb
- Posts: 3107
- Joined: Sun Jul 12, 2009 11:25 pm
Re: Checking if a letter was type into a form
rockinliam wrote:Yey time for one of my favourite functions
Edit: Damn lol spirit posted whilst i was reading an email...Code: Select all
<?php if (is_numeric($coinsADD)) { echo "You have added $coinsADD coins to your pile..."; } else { echo "TYPE NUMBERS YOU STUPID PERSON"; } ?>
Muahahahahaha
-
Baseball435
- Posts: 548
- Joined: Sun May 30, 2010 3:49 am
Re: Checking if a letter was type into a form
Thanks for all the answers guys 
Re: Checking if a letter was type into a form
And thanks from me as well, cause that seems a good one to try and remember! 

