Re: Looking for an easier regex check...

From: Date: Mon, 29 Apr 2002 20:33:52 +0000
Subject: Re: Looking for an easier regex check...
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-95249@lists.php.net to get a copy of this message
Worked great only you forgot to escape the carat character. Thanks for the help. Josh "Miguel Cruz" <mnc@stoic.net> wrote in message news:Pine.LNX.4.44.0204291516010.11066-100000@stoic.net... > On Mon, 29 Apr 2002, 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. > > I'm surprised you get a parse error. I'd expect you would get a runtime > error like REG_ERANGE. > > Anyway, you need to escape all the characters that have special meanings > in regular expressions. Try something like: > > ereg("[~!@#\$%^&\*(){}\-\+=|\\/\.,<>'\":;\[\]a-zA-Z0-9]", > $string); > > > 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? > > miguel >

« previous php.general (#95249) next »