RE: [PHP] Ensuring that variable contains a number
| From: | Brad Fuller | Date: | Wed, 06 Dec 2006 20:20:03 +0000 |
| Subject: | RE: [PHP] Ensuring that variable contains a number | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-245584@lists.php.net to get a copy of this message | ||
> How can I ensure that a variable contains a postive integer number?
> I'm currently using this code:
>
> $number=(10000-$number);
> $number=(10000-$number);
> if ( $number<1 ) { $number=1; }
>
> But I'm sure that there is a better way. What would that be?
this will check that $input is a positive integer.
if(preg_match("/^\d+$/", $input)) {
// OK
} else {
// NOT OK
}