[thelist] PHP: is_numeric... that's the question...

Drew Trusz drew.trusz at gmail.com
Thu Jan 18 08:12:56 CST 2007


On 1/18/07, Tris <beertastic at gmail.com> wrote:
> Indeed..
> so using this:
> return preg_match("/\d{1,8}/", is_numeric($usercode));
> still doesn't work, I can enter a numeric string of 9 or more
> characters and it's accepted? yet the {1,8} should stop at 8
> characters right???
>
> OHHHH, It IS finding strings of 8 characters within the whole string...
>
> I started with this code:
> =======================
>         $codeLength = strlen($usercode);
>         $codeInt = is_numeric($usercode);
>         if ((($codeLength == 0) || ($codeLength > 8)) || (!$codeInt)) {
>                 return false;
>         } else {
>                 return true;
>         }
> =======================
>
> Should I just stick to that, or is there a way to do it with one line
> and regular expresions?
>
> Sigh...
> is it Friday yet?
>
>
>
To borrow from Perl -- TIMTOWTDI (There Is More Than One Way To Do It)

Or, if it ain't broke, don't fix it.



More information about the thelist mailing list