Forum : How can I check a value entered in a field on my form is a number?
Brief description  about Online courses   join in Online courses
View Abhijit  Paul 's Profile

How can I check a value entered in a field on my form is a number?

How can I check a value entered in a field on my form is a number?????
Asked by Abhijit Paul | Mar 17, 2010 |  Reply now
Replies (1)
View teacher siliconindia 's Profile
Hi Abhijit,
There are several ways that you can check that this is the case. One of the simplest ways is to use a dedicated function, is_numeric - just pass it the value and it'll return true or false depending on whether it is a number or not.
Here's an example:
<?php
$formvalue = "57a";
if(is_numeric($formvalue)) { echo "Is a number"; } else { echo "Not a number"; }
?>
This prints 'Not a number' in this instance.
Mar 17, 2010