Re: Verifying a certain amount of numbers

From: Date: Wed, 16 Jul 2003 15:56:20 +0000
Subject: Re: Verifying a certain amount of numbers
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-155451@lists.php.net to get a copy of this message
Yes, use preg_match("/^[0-9]{6}$/",$str) since it takes care of both number and length. You dont want to you is_numeric(), because that will match "4e5", etc..etc.. Brent Baisley wrote:
I'm pretty sure there will be a problem with using the is_int() function. A similar problem was discussed a few weeks ago on this list and is_int() will return true for a "number" like 1000e2. The "e" being treated as an exponential representation of an integer. It might be more reliable to add or subtract 0 from the "string" and see if it changes. Something like: if( (strlen($str)==6) && ( strcmp(($str-0),$str)==0)) It may just be easier to use ereg if you won't be looping through a bunch of numbers. I don't know what the performance difference is between the above function and ereg or preg. On Wednesday, July 16, 2003, at 09:43 AM, Justin French wrote:
I tested
    if( (strlen($str) == 6) && (is_int($str)) )
vs
    if(ereg('^[0-9]{6}$',$str))


« previous php.general (#155451) next »