3

I want my user password have the rule like:

  1. at least one alphabet, at least one number.
  2. can include special characters (almost all special characters in keybord)
  3. length more than 8.

this is my regular expression

/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d!"#$%&'()*+,-.\/:;<=>?@[\]^_`{|}~]{8,}$/

but it does not match the back slash . for example ,the password "3e5t1qa2w\" will fail.

I use laravel(php framework) validation ,so the full code is this:

        'password' => array(
            'sometimes',
            'required',
            'between:8,32',
            'regex:/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d!"#$%&\'()*+,-.\/:;<=>?@[\]^_`{|}~]{8,}$/'
        ),

here is the real code enter image description here

and this one which use two back slash doesnot work too. enter image description here

Does someone knows why?

chii
  • 2,111
  • 3
  • 17
  • 21

2 Answers2

2

Your solution didn't work for me in Laravel 5.4., but using 4 backslashes did (at the near end). I'll leave it here if someone has the same problem:

/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d!"#$%&'()*+,-.\/:;<=>?@[\]^_`{|}~\\\\]{8,}$/

DEMO

Ivan Loler
  • 83
  • 1
  • 11
0

this one worked:

enter image description here

As MateoConLechuga said, the "]" may cause the problem. so I escape the "[" and "]" with back slash which meas they are just the "character".

and this link Right way to escape backslash [ \ ] in PHP regex? helped me that to match back slash i have to write it for three(or four) times.

Community
  • 1
  • 1
chii
  • 2,111
  • 3
  • 17
  • 21