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

Tris beertastic at gmail.com
Thu Jan 18 06:11:01 CST 2007


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?



On 18/01/07, Drew Trusz <drew.trusz at gmail.com> wrote:
> > anyhoo, next I wanna check to see if a usercode is only numeric, and
> > 1-8 characters long..
> >
>
> > I tried:
> > return preg_match("[^a-zA-Z][0-9]{1,8}", $usercode);
> > But it was accepted if there were any numbers in teh text.. that's bad!
> >
> > thoughts?
> >
> >
> Don't look for alphas when you want numeric. You don't want a match on
> [a-zA-Z] only on 0-9 with the appropriate length.
>
> Nice to see Szasz quoted.
>
> drew
> --
>
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !
>


-- 
When a person can no longer laugh at himself, it is time for others to
laugh at him.
Thomas Szasz



More information about the thelist mailing list