Tell us what’s happening:
I don’t get this code to work. It should detect an error only if there it starts with a number, has two consecutives numbers and should be at least 5 characters long. But it detects also if there is a number alone
like “D9a99aa”
Your code so far
let sampleWord = “D9a99aa”;
let pwRegex = /(?=\w{5,})^(?!\d)(?=\D*\d{2})/; // Change this line
let result = pwRegex.test(sampleWord);
let sampleWord = "Da99aa";
let pwRegex = /(?=\w{5,})^(?=\D+)(?=\D+\d{2})/; // Change this line
let result = pwRegex.test(sampleWord);
console.log(result)
//(?=\w{5,})(?!\d)(?=\D*\d{2})
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36
.
Challenge: Positive and Negative Lookahead
Link to the challenge: