Jump to content


Photo

Quick is_numeric() Question


  • Please log in to reply
4 replies to this topic

#1 Spunge

Spunge
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 04 September 2006 - 09:39 PM

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:

elseif ((! is_numeric($a)) || (! is_numeric($b)) || (! is_numeric($c))) {
echo " Please enter only numbers.";}

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?

#2 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 04 September 2006 - 09:57 PM

regular expressions

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#3 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 04 September 2006 - 10:19 PM

http://forums.invisi...hp/t183068.html

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#4 Spunge

Spunge
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 05 September 2006 - 01:16 AM

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.

#5 Unknown User

Unknown User
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 05 September 2006 - 01:24 AM

Can't you just embed an if in the elseif statement you have, checking that its not equal to 0?

elseif ((! is_numeric($a)) || (! is_numeric($b)) || (! is_numeric($c))) 
  {
    if( $a != '0' && $B != '0' && $c != '0')
      {
         echo " Please enter only numbers.";
      } 
  }
sorry if i'm completly wrong, new to php




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users