Re: reg exp help

From: Date: Mon, 23 Jul 2001 08:12:04 +0000
Subject: Re: reg exp help
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-59151@lists.php.net to get a copy of this message
Hi Justin, for the username, you can use: if (!preg_match("/^[a-z0-9]*$/", $username)) { // error } else { // ok } The ^ means start of the string, the characters between the [ and ] are ones that we want, the * means however many times, and the $ means the end of the line / string. So if there isn't a match against lower case letters and numbers throughout the string (from start to finish), there's an error. I'd advise you to go more complex with the email address. James. "Justin French" <justin@indent.com.au> wrote in message news:3B5BA0FB.8FCF57DB@indent.com.au... > hi all, > > two quick reg exp problems: > > one: > $username must only contain a-z lowercase, 0-9, no spaces, no other characters. > what would the regexp be? > > if(ereg("????????????????", $username)) { $valid = "yes" } else { $valid > = "no") > > > two: > i want to do a really small email validation, just to make sure the > email probably right, as in: > anything@anything.anything > > what's the best reg exp to use. > > > i'm aware there are email validating script out there, but I want to > learn for myself > > > > many thanks in advance > > > justin french

« previous php.general (#59151) next »