fubowl Posted November 1, 2010 Share Posted November 1, 2010 Taken from http://php.net/manual/en/function.is-numeric.php <?php $tests = array( "42", 1337, "1e4", "not numeric", Array(), 9.1 ); foreach ($tests as $element) { if (is_numeric($element)) { echo "'{$element}' is numeric", PHP_EOL; } else { echo "'{$element}' is NOT numeric", PHP_EOL; } } ?> Outputs: '42' is numeric '1337' is numeric '1e4' is numeric 'not numeric' is NOT numeric 'Array' is NOT numeric '9.1' is numeric WHY does 1e4 validate as TRUE using is_numeric? Quote Link to comment https://forums.phpfreaks.com/topic/217444-is_numeric-question/ Share on other sites More sharing options...
Pikachu2000 Posted November 1, 2010 Share Posted November 1, 2010 It's an exponential number. Quote Link to comment https://forums.phpfreaks.com/topic/217444-is_numeric-question/#findComment-1128938 Share on other sites More sharing options...
fubowl Posted November 1, 2010 Author Share Posted November 1, 2010 Ha. I see. Well I guess I'd have to use a different function since I don't see a way of removing that option. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/217444-is_numeric-question/#findComment-1128981 Share on other sites More sharing options...
Pikachu2000 Posted November 1, 2010 Share Posted November 1, 2010 I think you're probably looking for ctype_digit() Quote Link to comment https://forums.phpfreaks.com/topic/217444-is_numeric-question/#findComment-1128983 Share on other sites More sharing options...
Andy-H Posted November 1, 2010 Share Posted November 1, 2010 filter_var $options['options']['min_range'] = 0; $options['options']['max_range'] = 1337000; $options['options']['default'] = 0; if ( filter_var($intVar, FILTER_VALIDATE_INT) ) { // valid integer between 0 and 1337000 } else { // filter failed and returned 0 } Quote Link to comment https://forums.phpfreaks.com/topic/217444-is_numeric-question/#findComment-1128987 Share on other sites More sharing options...
salathe Posted November 1, 2010 Share Posted November 1, 2010 Andy-H, you might want to use the $options in the call to filter_var(). (P.S. If Andy edits his post, this won't make much sense.) Quote Link to comment https://forums.phpfreaks.com/topic/217444-is_numeric-question/#findComment-1129010 Share on other sites More sharing options...
Andy-H Posted November 1, 2010 Share Posted November 1, 2010 haha duhh Well spotted Quote Link to comment https://forums.phpfreaks.com/topic/217444-is_numeric-question/#findComment-1129012 Share on other sites More sharing options...
fubowl Posted March 18, 2011 Author Share Posted March 18, 2011 I think you're probably looking for ctype_digit() Certainly. Thanks Pikachu2000. Quote Link to comment https://forums.phpfreaks.com/topic/217444-is_numeric-question/#findComment-1189070 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.