mkosmosports Posted January 20, 2007 Share Posted January 20, 2007 How can I write a condition, if $variable is a digit? I have numbers and words in a table. Is there any simple way to write that condition?Thanks. Link to comment https://forums.phpfreaks.com/topic/34948-is-it-a-digit/ Share on other sites More sharing options...
Jessica Posted January 20, 2007 Share Posted January 20, 2007 if(intval($var)){}Or you could use is-numeric()http://us3.php.net/manual/en/function.is-numeric.php Link to comment https://forums.phpfreaks.com/topic/34948-is-it-a-digit/#findComment-164798 Share on other sites More sharing options...
tauchai83 Posted January 20, 2007 Share Posted January 20, 2007 yes..tat will definitely work! Link to comment https://forums.phpfreaks.com/topic/34948-is-it-a-digit/#findComment-164800 Share on other sites More sharing options...
ShogunWarrior Posted January 20, 2007 Share Posted January 20, 2007 You could alternatively use:[code]$input = '88';$match = preg_match("/^[0-9]+$/",$input);if( $match ){ //wow, it is a number}[/code]This version will check that it is a single digit (0-9):[code]$input = '88';$match = preg_match("/^[0-9]{1}$/",$input);if( $match ){ //wow, it is a single digit}[/code]Or to simply check it is a number:[code]if( is_numeric( $input ) ){}[/code] Link to comment https://forums.phpfreaks.com/topic/34948-is-it-a-digit/#findComment-164801 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.