Powered by InterCreatives | Site Map
Search:
NewSourceMedia Popular Tutorials: PHP Javascripts Web Hosting
SoftwareTutorials
CATEGORIES
Job Listings
 
Home / PHP / Math

PHP Validation Numbers Only From


Question:

How to validate number values to and block all letters and symbol in a form.

Answer:

You can check the value or convert the value to an integer (number).

1) Check a value using is_int() to finds whether the given variable is an integer

<?
if(is_int($variable))
echo "Pass test";
else
echo "Please use only numbers";
?>

2) Note: 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().

<?
if(is_numeric($variable))
echo "Pass test";
else
echo "Please use only numbers";
?>

3) Convert the value to an integer (number) using settype.

<?php
$foo = "5bar"; // string
$bar = true; // boolean

settype($foo, "integer"); // $foo is now 5 (integer)
settype($bar, "string"); // $bar is now "1" (string)
?>

or you can use int to do the trick.


<?
$int=593; // $int is a integer
$int.=""; // $int is now a string
?>

Next PHP Page:
1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  [29]  30  31  32 





Hosting by iPowerWeb.com - 50 Gb for $7.95