[Solved] regular expression for length 6 to 20 characters with upper and lower case alphabets and numeric character support


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

  1. The range {6,20}
  2. 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