PHP Quicky - Verification of user input: Digits
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:
$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):
if (!empty($value ) && is_numeric($value)) { ..do something }
-
fazlerocks -
Thanks
{{ DiscussionBoard.errors[3182056].message }} -
-
jameswatson2002 -
Thanks
{{ DiscussionBoard.errors[3182321].message }} -