Regex Expression Password Validation; 1 Uppercase; 1 Lowercase; 1 Number; length of 6 – 20

function valPassword($Password){

$pRegex = ‘/(?-i)(?m)^(?=.*?\d)(?=.*?[a-z])(?=.*?[A-Z])[a-zA-Z].{6,20}$/’;

if ( preg_match($pRegex, $Password)) { return TRUE; }
return FALSE;

}

Or this also works nicely:

function valPassword($Password)

{

if(
ctype_alnum($Password) // numbers & digits only
&& strlen($Password)>6 // at least 7 chars
//&& strlen($password)<21 // at most 20 chars
&& preg_match(‘`[A-Z]`’,$Password) // at least one upper case
&& preg_match(‘`[a-z]`’,$Password) // at least one lower case
&& preg_match(‘`[0-9]`’,$Password) // at least one digit

)

{

return TRUE;

}
return FALSE;

}

Resource:

http://regexlib.com/REDetails.aspx?regexp_id=31

Comments are closed.