Thread: Validating Whole Numbers

Validating Whole Numbers

From
"Krog, Kenneth"
Date:

Is there a quick way to validate whole numbers for instance you can validate
a number

if (is_numeric($x)
{
output
}
else
{
output
}

Thanks in advance








Re: Validating Whole Numbers

From
Jean-Luc Lachance
Date:
How about:

WHERE x ~ '^[0-9]*$'


"Krog, Kenneth" wrote:
>
> Is there a quick way to validate whole numbers for instance you can validate
> a number
>
> if (is_numeric($x)
> {
> output
> }
> else
> {
> output
> }
>
> Thanks in advance
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly

Re: Validating Whole Numbers

From
"Greg Sabino Mullane"
Date:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


> WHERE x ~ '^[0-9]*$'

You might want to change that asterick to a plus:

WHERE x ~ '^[0-9]+$'

so you don't get a false negative for an empty string.


Greg Sabino Mullane  greg@turnstep.com
PGP Key: 0x14964AC8 200203042125

-----BEGIN PGP SIGNATURE-----
Comment: http://www.turnstep.com/pgp.html

iD8DBQE8hC3FvJuQZxSWSsgRAmxnAJ9f/63H8JYnDjYc5VeVpOyrNxQm0ACaAjOY
3rmFQpTMVK+SrXJx7kOt9S0=
=PTUa
-----END PGP SIGNATURE-----