Reply to Re: [PHP] RegEx help

Your name:

Reply:


Posted by trlists on 10/20/17 11:13

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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация