Re: Regular expression problems

From: Date: Mon, 26 Feb 2001 05:53:28 +0000
Subject: Re: Regular expression problems
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-41642@lists.php.net to get a copy of this message
ok, that was my problem.... Was using ereg... All the places I read about how to do regular expressions (book, online...) did NOT clarify that \w and such would need preg.. Thanks! ""Simon Garner"" <sgarner@expio.co.nz> wrote in message news:022d01c09fa6$a2bbd460$1400a8c0@hq.nuverve.com... > From: "Dan Watt" <danwatt@mediaone.net> > > > Im trying to build a user login system, and when there is a new user, I > need > > to validate that they are usign using word characters ([0-9A-Za-z_] or > > \w)... I have TRIED MANY different regular expressions to test this, but > > none work. This seems so simple but I am missing something. I need a > > expression that returs true ONLY if ALL the characters match \w .... Any > > help would be appreciated. > > > > > > > <?php > $username = "johnny"; > > if (!eregi("[^A-Z0-9_-]", $username)) > { > echo "username OK"; > } > else > { > echo "bad username!"; > } > ?> > > Assuming you only want letters, numbers, underscores or hyphens. If you > really want \w you would need to use preg instead of ereg, and then you need > PCRE support in PHP. Or you could use ereg's character classes, I think the > pattern would look like: "[^[:alphanum:]]". However you are probably better > off using an explicit set of characters as I have shown, so that it is > obvious what is and is not allowed. > > > Cheers > > Simon Garner > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#41642) next »