I took an online JavaScript test where the 3rd problem was as follows:
Complete the checkPassword function, which should check if the password parameter adheres to the following rules:
- Must be longer than 6 characters.
- Allowed characters are lower or uppercase Latin alphabetic characters (a-z), numbers (0-9), and special characters +, $, #, \, / only.
- Must not have 3 or more consecutive numbers (e.g. "pass12p" is fine, but "pass125p" is not, because it contains "125")
>
My solution was as follows:
function checkPassword(password) {
return /^[a-zA-Z0-9\+\$\\\/#]{6,}$/.test(password) && !/[0-9]{3,}/.test(password);
}
This solution gave me the correct outputs for the given inputs.
But the ultimate test result told that the solution is just 75% correct sadly.
I think the perfect answer is expected to be a solution just with a single regular expression. Is there anyone who can give me a single regular expression that gives the same result? I am not so good at regular expression so please advise.
I appreciate your help in advance.