Here is a regex I have for validating a strong password:
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d!$\/%@]{6,20}$/
Criteria:
- Alphanumeric with special characters $/%@
- At least 1 number
- At least 1 lowercase letter
- At least 1 uppercase letter
- Length between 6-20 characters
- At least 1 special character $/%@
My main concern is regarding the last rule requiring at least one special character, specifically when that character is a forward slash.
When testing with '@' as the special character, it returns TRUE as expected:
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d!$/%@]{6,20}$/.test("Test@2")
However, using a forward slash like 'Test/2' does NOT return TRUE:
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d!$/%@]{6,20}$/.test("Test/2")
I even tried escaping the forward slash in both the regex and test string, but still couldn't get it to return TRUE.