Re: RegEx help

From: Date: Thu, 14 Apr 2005 17:56:57 +0000
Subject: Re: RegEx help
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-213105@lists.php.net to get a copy of this message
On 15 Apr 2005 Tom Rogers wrote: > BD> a. Must contain an 1 uppercase letter. [A-Z] > BD> b. Must contain 1 digit. [0-9] > BD> c. Must be a minimum of 7 characters in length. {7} > > BD> I'm not sure of how to build the correct syntax for using all 3 > BD> requirements together. > easier done seperately I think > if( > strlen($text) > 6 && > preg_match('/\d+/',$text) && > preg_match('/[A-Z]+/',$text) > ) { echo 'OK <br>'; To do it in one fell swoop you need to use lookahead assertions -- something like this: if (preg_match('/(?=.*[A-Z])(?=.*[0-9]).{7,}/', $text)) echo 'Valid!'; I believe this matches for any string that has at least one uppercase letter and one digit and is at least 7 characters long. However it allows other characters as well (not just A-Z and 0-9). Lots of possible variations there. -- Tom

« previous php.general (#213105) next »