Spunge Posted September 4, 2006 Share Posted September 4, 2006 I'm working on a small calculator script for personal use, and I'm having problems with limiting the input to only numbers. This is what I have:[code]elseif ((! is_numeric($a)) || (! is_numeric($b)) || (! is_numeric($c))) {echo " Please enter only numbers.";}[/code]It will filter out letters, but it also filters out 0s, which is not what I'm after. Anyone know a potential solution to make this treat 0s as a normal number? Quote Link to comment https://forums.phpfreaks.com/topic/19708-quick-is_numeric-question/ Share on other sites More sharing options...
Ninjakreborn Posted September 4, 2006 Share Posted September 4, 2006 regular expressions Quote Link to comment https://forums.phpfreaks.com/topic/19708-quick-is_numeric-question/#findComment-86023 Share on other sites More sharing options...
Ninjakreborn Posted September 4, 2006 Share Posted September 4, 2006 http://forums.invisionpower.com/lofiversion/index.php/t183068.html Quote Link to comment https://forums.phpfreaks.com/topic/19708-quick-is_numeric-question/#findComment-86035 Share on other sites More sharing options...
Spunge Posted September 5, 2006 Author Share Posted September 5, 2006 Thanks, but I'm still having problems. I've got to be missing something... No matter what I do, it's thinking zero is either not a number, or that the form is empty. Quote Link to comment https://forums.phpfreaks.com/topic/19708-quick-is_numeric-question/#findComment-86105 Share on other sites More sharing options...
Unknown User Posted September 5, 2006 Share Posted September 5, 2006 Can't you just embed an if in the elseif statement you have, checking that its not equal to 0?[code]elseif ((! is_numeric($a)) || (! is_numeric($b)) || (! is_numeric($c))) { if( $a != '0' && $B != '0' && $c != '0') { echo " Please enter only numbers."; } }[/code]sorry if i'm completly wrong, new to php Quote Link to comment https://forums.phpfreaks.com/topic/19708-quick-is_numeric-question/#findComment-86106 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.