$pattern = "/^([0-9]+)$/"; if (preg_match($pattern, $input)) echo "yes"; else echo "nope";