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? 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. 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. 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() 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 } 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.) 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 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. Link to comment https://forums.phpfreaks.com/topic/217444-is_numeric-question/#findComment-1189070 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.