Two false positives on "Restrict Possible Usernames"

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/regular-expressions/restrict-possible-usernames

I don’t know if reporting this is useful, but I’ll do it anyway just in case.

I assume the most common solution to this problem is:

let userCheck = /^[a-z][a-z]+\d*$|^[a-z]\d\d+$/i;

However, the page never checks for a username that starts with a letter and has more than two numbers after it (e.g., “A123”), making the “+” omissible and giving a false positive with

let userCheck = /^[a-z][a-z]+\d*$|^[a-z]\d\d$/i;

The second false positive is less important since you wouldn’t do this, but this also gives a false positive:

let userCheck =/^[a-z][a-z]+\d*$|^[a-z]\d\w$/i;

Witch shouldn’t be possible since it can’t have a number in the middle of the user name.

For clarity, both regexes are passing all current tests, but they are not giving correct results for some other usernames:

  • /^[a-z][a-z]+\d*$|^[a-z]\d\d+$/i doesn’t match valid usernames with more than two numbers at the end - i.e. A123.
  • /^[a-z][a-z]+\d*$|^[a-z]\d\w$/i is specifically matching, invalid, usernames with three characters having number in the middle, i.e. B3R.

Would you be interested in creating issue for this problem in the github repository?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.