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
?>
NewSourceMedia is providing links to these listings as
a courtesy, and makes no representations regarding the content or
any information related thereto. Any questions, complaints or claims
regarding the downloaded content or details must be directed to the appropriate
publisher. We do not encourage or condone the use of any
software in violation of applicable laws.