I'm looking for a method that would allow me to check for valid IDs in my system.
They're by definition:
- positive, not 0,
- a whole number, but might be bigger than integer size
- come as either string or number
I'd like to know what you think is the most elegant way of validating this. Candidates that fail are:
is_int(), because it's valid for negative numbers, AND because of the integer size limitis_numeric(), because it'd valid for float, or, say, having an exponential part like this +0123.45e6ctype_digit()with casting the input to string, because this would be valid: "0000"
I've so far settled with this:
preg_match('/^[1-9][0-9]*$/',(string)$id);
Can anyone come up with an alternative?