checking a password for upper lower numbers and symbols

后端 未结 3 452
故里飘歌
故里飘歌 2020-12-16 05:32

I am using the below script to check my passwords for length, uppercase, lowercase and numbers.

How could I change it to make it check FOR symbols instead of against

相关标签:
3条回答
  • 2020-12-16 05:57

    Tests if the input consists of 6 or more ASCII characters.The input must contain at least one upper case letter, one lower case letter and one digit.

    if(preg_match('/\A(?=[\x20-\x7E]*?[A-Z])(?=[\x20-\x7E]*?[a-z])(?=[\x20-\x7E]*?[0-9])[\x20-\x7E]{6,}\z/' $password))
        echo("valid password");
    
    0 讨论(0)
  • 2020-12-16 06:20

    your desired regex is below

       $pattern = ' ^.*(?=.{7,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$ ';
    
       preg_match($pattern,$password);
    

    DEMO

    0 讨论(0)
  • 2020-12-16 06:21

    Either you determine a list of valid symbols:

    preg_match('`[\$\*\.,+\-=@]`',$password)
    

    or you can look for anything that isn't alnum:

    preg_match('`[^0-9a-zA-Z]`',$password)
    
    0 讨论(0)
提交回复
热议问题