I'd use a regular expression to ensure the string contains only digits and is a reasonable length, something like this (starting at the beginning of the string in $var, require from 1 to 8 digits, followed by the end of the string). Anything else is either a typo or someone deliberately trying to make your code fail.
if (preg_match("/^\\d{1,8}$/", $var) )
...