Re: Looking for an easier regex check...
| From: | CC Zona | Date: | Mon, 29 Apr 2002 21:01:49 +0000 |
| Subject: | Re: Looking for an easier regex check... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-95267@lists.php.net to get a copy of this message | ||
In article <20020429200820.27938.qmail@pb1.pair.com>,
josh@acsurf.net (Joshua E Minnie) wrote:
> Does anybody know of a good way to make sure that a string contains ONLY
> certain characters. I tried using
> ereg("[~`!@#$%^&*(){}-+=|\\/.,<>'\":;\[\]]", $string); but I get
> parse
> errors. Besides that I only want the characters A-Za-z0-9_ in $string. Is
> there is simpler way to ensure this rather than checking to see if any of
> the characters I don't want are in there?
if(preg_match("/\W/",$string))
{
echo "Bad characters.";
}
<http://php.net/preg-match>
<http://www.php.net/pcre.pattern.syntax>
--
CC