Working Snippet
var password = prompt("Enter password", "1234567890Aa1234567890");
var regex = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,20}$/;
console.log("Password valid?: ", regex.test(password));
The regex had 2 things missing
- The range
{6,20}
- Plus, the
^
and$
, in the start and end of the regex. They signify, that the regex should apply end to end, and not a subset of the string.
0
solved regular expression for length 6 to 20 characters with upper and lower case alphabets and numeric character support