Re: Regular expression

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

 



On 2/14/06, Patrick <pafo@xxxxxxxx> 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 - ifonly 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 assertionto check):
(?=[!#%&$£\w]{5})
Zero or more non-punctuation characters, followed by a a punctuationcharacter, 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

[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