RE: FILTER_VALIDATE_INT - newbie question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 2009-10-07 at 11:19 +0100, MEM wrote:

> > Well, at a guess, if a number is 0, PHP see's that as equivalent to a
> > false. 
> 
> In this case, shouldn't php ignore the 0 as 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.
> 
> This happens with two different php configurations... Is it common to have this kind of limit on php configuration?
> Is this something that I need to be aware of?
> 
> 
> > 
> > For things this simple, 
> THIS IS NOT SIMPLE !!! :) Newbie blood is in there! :p
> Kidding. ;)
> 
> > 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.
> 
> I will absolutely considerer the use of your regex. Thanks a lot.
> 
> 
> Before your e-mail, I've considering the use of this:
> if (!is_numeric($telefone))
> {
>   $erros['numberofsomething'] = 'Error - only numbers please.';
> }
> 
> In the case we need to validate other ints, that are not phones for example, only an unlimited range of ints,
> and we want to store that values on a database, should we have special considerations regarding the use of is_numeric ?
> 
> 
> 
> Thanks a lot,
> Márcio
> 

Well, it was only a guess, but if you look at the integer limit on
32-bit systems, you'll see that the upper limit for numbers is
2147483647 (or 2^31-1) which would explain maybe your upper limit
problem.

Also, I think you're getting confused over the zero with exactly what
you are asking PHP to do. filter_var() returns true if the filter
matches. If the 0 match is returned as a false, then filter_var() will
return false. You're then inverting that with a !, all of which is
inside an if() statement. Essentially this would mean that if the filter
returns false then the instructions inside of the if statement are
carried out.

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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux