1r'^
2 (?=.*[A-Z]) // should contain at least one upper case
3 (?=.*[a-z]) // should contain at least one lower case
4 (?=.*?[0-9]) // should contain at least one digit
5 (?=.*?[!@#\$&*~]) // should contain at least one Special character
6 .{8,} // Must be at least 8 characters in length
7$
8
1function validate(password) {
2 return /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])[A-Za-z0-9]{6,}$/.test(password);
3}
4
5Explanation:
6
7^ // start of input
8(?=.*?[A-Z]) // Lookahead to make sure there is at least one upper case letter
9(?=.*?[a-z]) // Lookahead to make sure there is at least one lower case letter
10(?=.*?[0-9]) // Lookahead to make sure there is at least one number
11[A-Za-z0-9]{6,} // Make sure there are at least 6 characters of [A-Za-z0-9]
12$ // end of input
13