On 2/14/06, Patrick <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I am trying to validate a password, but havent figured out the pattern for
> it yet.
> The password must contain atleast 6 characters
> a-zA-Z0-9_
> must start with a
> a-zA-Z
> and must have atleast one of the following characters
> !#%&$£


As Curt said, it's probably better to do this programatically - if
only so you can work out what it's doing six months down the road.

However if you want to know to do it as a regexp:

start with the letters a-z.

^[a-z]

At least 5 legal characters following that  (use a lookahead assertion
to check):

(?=[!#%&$£\w]{5})

Zero or more non-punctuation characters, followed by a a punctuation
character, followed zero or more of any valid character.

\w*[!#%&$£][!#%&$£\w]*

And then anchor the end of the string with a $.

Put all that together with a bit of case insensitivity and you get.

$regexp = '/^[a-z](?=[!#%&$£\w]{5})\w*[!#%&$£][!#%&$£\w]*$/i';

$status = preg_match($regexp, $password) ? 'PASS' : 'FAIL';

  -robin

Reply via email to