Archive for the ‘Regular Expressions’ Category

Perl valid email regular expression

Tuesday, February 1st, 2011

# Check for valid email address

/
^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$
/

Php simple phone format

Monday, March 8th, 2010

$phone = 3334449999;
$phone = preg_replace(“/([0-9a-zA-Z]{3})([0-9a-zA-Z]{3})([0-9a-zA-Z]{4})/”, “($1) $2-$3″, $phone);

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

Tuesday, March 2nd, 2010

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