Re: is_numeric

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

 



On Wed, May 4, 2005 3:51 am, pete M said:
> not a php expert but have filed this bug report re validating
> is_numeric('3e0');
> http://bugs.php.net/bug.php?id=32943
>
> Now tried
>
>    function isnumeric($n) {
>     if (ereg("^[0-9]{1,50}.?[0-9]{0,50}$", $n)) {
>       return true;
>     } else {
>       return false;
>     }
>    }
>
> and that doent seem to work either..
>
> any ideas.. need to validate anything without 0-9 and a dot within

. is a special character in Regex, so your .? is going to match: "any
single character, or nothing"

You need \. for the Regular Expression, only you need \\ in PHP to get \

Plus $ would be interpreted as the start of variable inside of "" in PHP,
so to be really clear, I'd escape that as well:

"^[0-9]{1,50}\\.?[0-9]{0,50}\$"

The 50-character limit seems rather arbitrary and silly, actually...

Perhaps just a + and * instead of the {1,50} and {0,50} as well.

You've also completely missed all the negative numbers, by the way.

Maybe you want to read through the User Contributed notes at
http://php.net/ereg and http://php.net/pcre and find a solution that more
closely matches the real world.

For that matter, Euler notation is quite common, and maybe it's really
best if you just use the built-in function, and accept that the 'e'
notation is valid.

YMMV

-- 
Like Music?
http://l-i-e.com/artists.htm

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


[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