Re: RegEx help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux