Hello all, Time for another PHP quicky.
PHP Quicky - Verification of user input: Digits
3
Hello all,
Time for another PHP quicky.
If you need to verify if a submitted field is a numerical value, PHP offers a handy function called :
is_numeric()
What this function does is return a 'true' if the value is an integer or numeric string, 'false' otherwise. For example:
One thing to remember when using this function is that testing the number (or numerical string) '0' will return true.
I often use this test in script to make sure the value is a valid id (excludes '0' as an ID):
WP4H
Time for another PHP quicky.
If you need to verify if a submitted field is a numerical value, PHP offers a handy function called :
is_numeric()
What this function does is return a 'true' if the value is an integer or numeric string, 'false' otherwise. For example:
Code:
$number = 45; echo is_numeric($number); // prints 1 -> value is numeric $number = '3'; echo is_numeric($number); // prints 1 -> value is numeric $number = 'abc'; echo is_numeric($number); // prints 0 -> value is NOT numeric
I often use this test in script to make sure the value is a valid id (excludes '0' as an ID):
Code:
if (!empty($value ) && is_numeric($value)) {
..do something
} - fazlerocks
- jameswatson2002
Next Topics on Trending Feed
-
3