I have the following simple code which check if the password contains at least two lowercases.
preg_match("/^(?=.*[a-z].*[a-z])+$/")
But this gave me the following error message: Compilation failed : nothing to repeat at offset 19 .
I can't figure where I'm wrong
Later Edit
The following code which checks if i have at least two special characters works well:
preg_match("/^(?=.*[!@#$%^&*].*[!@#$%^&*])[a-zA-Z_!@#%^&*]+$/"
)
The (?= )
defines an assertion, you can not repeat an assertion. Did you mean to use (?: )
?
$data = array('ab', '123a345b', '123');
foreach ($data as $subject) {
$found = preg_match("/^(?:.*[a-z].*[a-z])+$/", $subject, $match);
var_dump($found, $match);
}
Output:
int(1)
array(1) {
[0]=>
string(2) "ab"
}
int(1)
array(1) {
[0]=>
string(8) "123a345b"
}
int(0)
array(0) {
}
Try this
<?php
preg_match("/^(.*[a-z].*[a-z].*)$/", "2313123g123123u123", $result);
var_dump($result);
preg_match("/^(.*[a-z].*[a-z].*)$/", "65665656s656565", $result);
var_dump($result);
?>
result
array(2) {
[0]=>
string(18) "2313123g123123u123"
[1]=>
string(18) "2313123g123123u123"
}
array(0) {
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.