I'm working on a pattern for a password with the following requirements:
I am using this regex:
var passReg = /^(?=^[ -~]{6,64}$)(?=.*([a-z][A-Z]))(?=.*[0-9])(.*[ -/|:-@|\[-`|{-~]).+$/;
However, it does not work as expected.
You must be looking for this regex:
^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[ -/:-@\[-`{-~]).{6,64}$
See demo
Here is explanation:
^
- Beginning of string(?=.*[a-z])
- A positive look-ahead to require a lowercase letter(?=.*[A-Z])
- A positive look-ahead to require an uppercase letter(?=.*[0-9])
- A positive look-ahead to require a digit(?=.*[ -/:-@\[-
{-~])` - A positive look-ahead to require a special character.{6,64}
- Any character (but a newline), 6 to 64 occurrences$
- End of string.