Re: Alphanumeric Strings

From: Date: Thu, 14 Sep 2000 23:07:04 +0000
Subject: Re: Alphanumeric Strings
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-16858@lists.php.net to get a copy of this message
Jason Granum writes: > This returns true though if the string is "This is a @#&$#@#% test" > Alphanumeric should only be a-z 0-9 and _ correct? ARGH! Yes. It should be something more like this: if (ereg('[^ [:alnum:]]', $string)) { echo "Contains non-alphanumeric/space characters"; } else { echo "Contains only alphanumerics and spaces"; } If you want it to be allowed to include all whitespace (tabs, spaces, newlines, etc), use this instead: if (ereg('[^[:space:][:alnum:]]', $string)) { echo "Contains non-alphanumeric/whitespace characters"; } else { echo "Contains only alphanumerics and whitespace"; } > > if (ereg('[[:alnum:]]', $string)) { > > /* do something */ > > } Hmph. Always good to *test* before posting, I s'pose. ;) -- +----------------------------------------------------------------+ |Torben Wilson <torben@php.net> Netmill iTech| |http://www.coastnet.com/~torben http://www.netmill.fi| |Ph: 1 250 383-9735 torben@netmill.fi| +----------------------------------------------------------------+

« previous php.general (#16858) next »