FILTER_VALIDATE_INT unexpected result

229 Views Asked by At

I'm using the following code:

if(!filter_var($Postings['remainingTokens'], FILTER_VALIDATE_INT, array('min-range' => 1))){

$this->redirect(array('upgrade', 'id'=>$id));
}

When I have $Postings['remaingTokens'] equal to 1 or higher it works fine and doesn't execute within the if statement. If I have a negative value though it still doesn't execute the redirect(). Why is this the case? Apologies if this is simple?

Jonny

2

There are 2 best solutions below

1
On BEST ANSWER

It is spelled min_range not min-range.

0
On

For those wondering how I fixed the negative number issue also: I did the following:

        $options = array(
    'options' => array(
        'min_range' => 1
        )
    );
filter_var($jobPostings['remainingTokens'], FILTER_VALIDATE_INT, $options)

Hopefully that is of some use to someone.