I am building a password checker - I have a simple requirement for at least three lowercase non-consecutive letters for now and either I have a large misunderstanding of regexes, or something else.
I have written the following code:
var password = 'mYpAsSwOrD',
r = new RegExp('[a-z]{3,}', 'g');
console.log(password.match(r)); // null
console.log(r.test(password)); // false
Also, is the 'g' flag needed? Does the quantifier not provide the same functionality effectively?
What is the better comparison? Matching the regex against the string (first example); or testing the string against the regex (second example)?
requirement for at least three lowercase letters. Can you please explain this part more?[a-z]{3,}will not match capitol letter or numbers os specail characters.Is this a requirement?