Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2008
    Posts
    17
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Validating for negative integer values

    is there a function similiar to all the is_ ones that would validate if a variable is a negative or positive integer? I tried the following for the same effect, but no luck with it:

    PHP Code:
    "bds":4,

    if(
    strpos(strval($v[bds]),'-') === false) { echo "is negative"; } 

  • #2
    New Coder
    Join Date
    Mar 2009
    Location
    Chicago, IL
    Posts
    69
    Thanks
    0
    Thanked 15 Times in 15 Posts
    Is there a reason you can't use:

    PHP Code:
    if ($v[bds] < 0) { echo "is negative"; } 

  • #3
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,519
    Thanks
    114
    Thanked 110 Times in 109 Posts
    You could use the is_int to test that its an integer and then just check its less than 0

    PHP Code:
    if(is_int($v[bds]) && $v[bds]<0)) { echo "nagative integer"; } 
    but is_int does validate if a variable is a negative or positive integer
    Last edited by timgolding; 03-20-2009 at 11:50 PM.
    You can not say you know how to do something, until you can teach it to someone else.

  • #4
    New Coder
    Join Date
    Feb 2009
    Posts
    36
    Thanks
    3
    Thanked 0 Times in 0 Posts
    How about:

    PHP Code:
    if(is_int(abs($v[bds])) && $v[bds]<0)) { echo "nagative integer"; } 
    Take the absolute value of the input first to determine if it is an integer...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •