2016-08-18 102 views
1
$password = 'pwd3000!'; 

if(!preg_match('/^(?=.{4,31}$)(?!.*(.)\1{4}). \w[\w.-]+\w$/', $password)){ 
    echo 'Your password is too easy'; 
} else { 
    echo 'Your password is strong'; 
} 

如果密碼有4個以上重複字符,我想回顯'您的密碼太簡單了'。防止在密碼中重複字符

現在,當我運行代碼時,我得到'您的密碼太簡單了'。但它只有3個重複的字符串,而不是4.我該如何解決這個問題?

+0

可能dublicate http://stackoverflow.com/questions/20770148/how-to-prevent-the-user-from-repeating -a-character-more-three-times-in-the –

+0

過濾出重複的字符或*連續的*重複的字符? – castis

+0

@castis連續 – brewpixels

回答

1

試試這個:

$password = "aaaabb"; 
if (preg_match('/(\w)\1{3,}/', $password)) { 
    echo 'Your password is too easy'; 
} else { 
    echo 'Your password is strong'; 
} 

輸出:的

Your password is too easy