[Solved] PHP regex for validating password [closed]


Have a look at the preg_match() PHP function in the manual.

Quick Example:

<?php
// Check if the string is at least 8 chars long
if (strlen($password) < 8)
{
   // Password is too short
}


// Make the password "case insensitive"
$password = strtolower($password);


// Create the validation regex
$regex = '/^[a-z][\w!@#$%]+\d$/i';

// Validate the password
if (preg_match($regex, $password))
{
   // Password is valid
}
else
{
   // ... not valid
}

­

Regex Explanation:  
   ^           => begin of string
   [a-z]       => first character must be a letter
   [\w!@#$%]+  => chars in between can be digit, underscore, or symbol
   \d          => must end with a digit
   $           => end of string
   /i          => case insesitive

2

solved PHP regex for validating password [closed]