I have the following regex for testing a strong password:
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d!$\/%@]{6,20}$/
Rules:
My question is mostly about the last rule of minimum 1 special character when that character is a forward slash.
The following code, for special character @, returns TRUE as expected:
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d!$/%@]{6,20}$/.test("Test@2")
But the following code, for forward slash, does NOT:
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d!$/%@]{6,20}$/.test("Test/2")
I also tried to escape both the regex and the test string forward slash with / but that does not seem to return TRUE
My mistake was in the first validation of the special characters. The working solution is:
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!$\/%@])[A-Za-z\d!$\/%@]{6,20}$/