Reputation: 711
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.
Upvotes: 2
Views: 5719
Reputation: 275
Input Password and Submit [8 to 25 characters which contain at least one lowercase letter, one uppercase letter, one numeric digit, and one special character]
/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9])(?!.*\s).{8,25}$/;
Upvotes: 0
Reputation: 325
Are consider special non-whitespace characters. I think this is complite list:
! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~
Try this one:
var passReg = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!"#$%&'()*+,-.\/:;<=>?\\@[\]^_`{|}~]).{6,64}$/;
Look at back reference for special characters. In character sets chars like \ and ] must be escaped.
Upvotes: 0
Reputation: 626747
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.Upvotes: 2