Restrict Possible Usernames-error

Restrict Possible Usernames-error
0

#1

Tell us what’s happening:
the “regex” i have mentioned is perfectly working with all the expressions given , when i am using in RegExr, but when i run it here it does not match for JACK, plz help.

Your code so far


let username = "JackOfAllTrades";
let userCheck = /[a-z]..+|[a-z][a-z]|[a-z].+\d$/gii; // Change this line
let result = userCheck.test(username);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/restrict-possible-usernames


#2

Thats because in your regex you havent included the matching for an Uppercase Letter since J in JackOfAllTrades is uppercase.
It should be [a-zA-Z]


#3

Yes he has, that’s what the i flag is for, but as it turns out, that’s the issue:

@adarshk010 the test won’t work with flags, you need to explicitly use [a-zA-Z]. This is failing of the test, not of the code. That being said:

  • You have an extra i
  • The code doesn’t match the description even though it will pass the tests - because . matches anything, [a-z].+\d$ never gets touched, and the tests will pass wherever the numbers appear in the string, not just at the end (The only numbers in the username have to be at the end. There can be zero or more of them at the end.)