Validating Whole Numbers

Started by Krog, Kennethabout 24 years ago3 messagesgeneral
Jump to latest
#1Krog, Kenneth
KAKrog@MassMutual.com

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

#2Jean-Luc Lachance
jllachan@nsd.ca
In reply to: Krog, Kenneth (#1)
Re: Validating Whole Numbers

How about:

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

"Krog, Kenneth" wrote:

Show quoted text

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

#3Greg Sabino Mullane
greg@turnstep.com
In reply to: Jean-Luc Lachance (#2)
Re: Validating Whole Numbers

-----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-----