note 112431 deleted from function.preg-match by googleguy
| From: | googleguy@php.net | Date: | Sun, 16 Jun 2013 10:24:34 +0000 |
| Subject: | note 112431 deleted from function.preg-match by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-195237@lists.php.net to get a copy of this message | ||
Note Submitter: debpal07 at gmail dot com
----
// Password Validation
public static function isValidPassword($password)
{
/*
Validation Rule:
1. Password must contain 8-15 alpha-numeric characters without spaces
2. Please use a combination of alphabets, numbers and special characters
(@, $, _, !, ~)
3. There must be at least one alphabet, one number and one special character.
*/
if(strlen($password) >= 8 && strlen($password) <= 15)
{
$patterns = array
(
"/[A-Za-z]{1,}[0-9]{1,}[@\$\_!~]{1,}/",
"/[0-9]{1,}[A-Za-z]{1,}[@\$\_!~]{1,}/",
"/[@\$\_!~]{1,}[0-9]{1,}[A-Za-z]{1,}/",
"/[@\$\_!~]{1,}[A-Za-z]{1,}[0-9]{1,}/",
"/[A-Za-z]{1,}[@\$\_!~]{1,}[0-9]{1,}/",
"/[0-9]{1,}[@\$\_!~]{1,}[A-Za-z]{1,}/"
);
foreach ($patterns as $pattern)
{
if(preg_match($pattern, $password)) return true;
}
}
return false;
}