Jump to content


Photo

Number Validate


  • Please log in to reply
2 replies to this topic

#1 ZoorBIS

ZoorBIS
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 14 June 2006 - 04:59 AM

Hi all,

Am having trouble trying to find a php function to check a number.

Have tried is_integer and is_int

What is the best way of checking / validating number.

The numbers can be anything like
1
1.22
3.333
3
4



#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 14 June 2006 - 05:05 AM

You also can try is_numeric:

[a href=\"http://www.php.net/is_numeric\" target=\"_blank\"]http://www.php.net/is_numeric[/a]

Or you can simply skip that and use typecasting

[a href=\"http://www.php.net/manual/en/language.types.type-juggling.php\" target=\"_blank\"]http://www.php.net/manual/en/language.type...pe-juggling.php[/a]
[a href=\"http://www.php.net/settype\" target=\"_blank\"]http://www.php.net/settype[/a]
~ D Kuang

#3 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 14 June 2006 - 05:07 AM

if ($whatever + 0 != 0) {
// $whatever must be a number
}

Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users