Jump to content

Archived

This topic is now archived and is closed to further replies.

Spunge

Quick is_numeric() Question

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.