SQL PHP HTML ASP JavaScript articles and free scripts to download
PHP Form Form post back

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


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>";

echo is_numeric($val); // Output 1

We can also use FILTER_VALIDATE_INT php filter to validate integer.
If you are checking any form input then take care of left or right space and use trim function before applying is_numeric function.
Post Comment This is for short comments only. Use the forum for more discussions.
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked

HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2015 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer