SQL PHP HTML ASP JavaScript articles and free scripts to download
 

is_numeric to validate number in php

We can use is_numeric function in PHP to check if a number or variable is numeric or not. This function we can use to check user inputs of a form on a component where we expect only numeric data can be entered. This function can check and take care of decimal and exponential numbers also. Here is the syntax

is_numeric(number);


The above checking will return true or false based on the value stored on number. Let us try some examples. The output of each type of checking is given at its right side within comments.

echo is_numeric(12.35);// Output 1
echo "<br>";
echo is_numeric(.35);// Output 1
echo "<br>";
echo is_numeric(10e9);// Output 1
echo "<br>";
echo is_numeric(+11e-9)? "T" :"F";// Output T
echo "<br>";
echo is_numeric("05.050.1") ? "T" : "F";// Output F
echo "<br>";

$val=13.58;
echo is_numeric($val); // Output 1


If you are checking any form input then take care of left or right space and use trim function before applying is_numeric function.




Further readings
All form components validation with post back and data locking
Checkbox
How to retain form data if validation fails?
How to retain data of a text box after submitting
Retaining status of a check box
Updating checkbox value from & to a table record.
Retaining selected data of a period button of a form
Retaining selected data of a drop down list box of a form
Handling drop down list box with multiple selection options using array
Validating Date: Checking if date exist
Email address validation in a form
Email validation using Ajax & PHP
PHP Form Validation
is_numeric to check numeric numbers
ctype_alnum to check alphanumeric characters data
ctype_alpha to check alphabetic characters data
How to take care of form & query string variables if Register global is OFF?
















Join Our Email List
Email:  
For Email Newsletters you can trust
Form handling
PHP Sections