1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Is_Numeric () PHP Function

By

Businesswoman typing on laptop
Paul Bradbury/OJO Images/Getty Images

Definition: The is_numeric () function is used to check if a value is a number. This could be used within an if () statement to treat numbers in one way and non-numbers in another. It will return true or false. Numeric strings consist of an optional sign (such as + or -), any number of digits, optional decimal point and optional exponent. It will also identify a hexadecimal number, but only on its own without a sign, decimal or exponent.

Also Known As: Is Numeric, Is Number

Examples:

 <?php 
 if (is_numeric (887)) 
 {
 echo "Yes";
 } else {
 echo "No";
 }
 ?>
 

Since 887 is a number, this should echo "Yes"

 

 <?php 
 if (is_numeric ("cake")) 
 {
 echo "Yes";
 } else {
 echo "No";
 }
 ?>
 

Since cake is not a number, this should echo "No"

Related Video
Basic PHP Syntax
Using PHP With HTML
  1. About.com
  2. Technology
  3. PHP / MySQL
  4. PHP Functions
  5. Is_Numeric () PHP Function

©2014 About.com. All rights reserved.