Jump to content

Archived

This topic is now archived and is closed to further replies.

ZoorBIS

Number Validate

Recommended Posts

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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
[code]if ($whatever + 0 != 0) {
// $whatever must be a number
}[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.