On Wed, 2009-10-07 at 10:57 +0100, MEM wrote:
> Hello all,
> 
> 
> I'm having this strange behavior, and I do not understanding why...
> 
> When I use FILTER_VALIDATE_INT I'm unable to get, on my input box, values
> starting with 0(zero), or values that are greater (in length) then 10
> digits.
> 
> I was expecting to be able to input the all range of integers.
> 
> 
> I've tried this:
> 
> if (!filter_var($telefone, FILTER_VALIDATE_INT))
> {
>    $erros['telefone'] = 'Invalid Teléfono - Only Numbers Allowed.';
> }
> 
> And this:
> if (!filter_var($telefone, FILTER_VALIDATE_INT, array("options" =>
> array("min_range"=>-1, "max_range"=>9999999999999))))
> {
>   $erros['telefone'] = 'Invalid Teléfono - Only Numbers Allowed.';
> }
> 
> And this:
> if (filter_var($telefone, FILTER_VALIDATE_INT, array("options" =>
> array("min_range"=>0, "max_range"=>99999999999999999))) == false )
> {
>   $erros['telefone'] = 'Invalid Teléfono - Only Numbers Allowed.';
> }
> 
> No success. :s
> 
> What am I not getting?
> 
> 
> Thanks,
> Márcio
> 
> 
> Ps- Anyone knows where can we grab a good source information about
> FILTER_VALIDATE_INT specifically?
> 
> 

Well, at a guess, if a number is 0, PHP see's that as equivalent to a
false. Also, numbers over 10 digits may be going over the limit for your
PHP install, assuming PHP actually attempts to convert the string to a
real integer for the purpose of the filter.

For things this simple, I've always tended to go with something like
this:

if(!preg_match('^[0-9 \+]$', $telefone))
{
  $erros['telefone'] = 'Invalid Teléfono - Only Numbers Allowed.';
}

Which will check for all common types of phone numbers, including those
where the user has put spaces in to separate groups of digits, and those
that contain the + for country codes.

Thanks,
Ash
http://www.ashleysheridan.co.uk




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to