Reputation: 27
$uppercase = preg_match('@[A-Z]@', $motpass);
$lowercase = preg_match('@[a-z]@', $motpass);
$number = preg_match('@[0-9]@', $motpass);
$special = preg_match('@[@#$%^&+=]@', $motpass); <---( PROBLEM HERE )
if (!$uppercase || !$lowercase || !$number || !$special || strlen($motpass) < 8)
{
$motpass_error='NO GOOD';
$error=true;
}
else
{
$motpass = $_POST['motpass'];
}
Im looking for regex (All specials Chararcter or Most )
Thanks in advance!
Upvotes: 0
Views: 252
Reputation: 51
'\w' matches word(alphabet or numeric) character where as '\W' matches non-word (special characters) character.
So using non-word character makes simple. Try below regex:
$special = preg_match('/\W+/', $string);
'+' in expression represent one or more word characters.
Upvotes: 1
Reputation: 720
You can try code like below.
$uppercase = preg_match('@[A-Z]@', $motpass);
$lowercase = preg_match('@[a-z]@', $motpass);
$number = preg_match('@[0-9]@', $motpass);
$special = preg_match('/[^a-zA-Z\d]/', $string);
OR
$uppercase = preg_match('@[A-Z]@', $motpass);
$lowercase = preg_match('@[a-z]@', $motpass);
$number = preg_match('@[0-9]@', $motpass);
$special = preg_match('/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$%^&]).*$/');
if (!$uppercase || !$lowercase || !$number || !$special || strlen($motpass) < 8)
{
$motpass_error='NO GOOD';
$error=true;
}
else
{
$motpass = $_POST['motpass'];
}
Upvotes: 1