Hi sorry for creating another of this similar topics…
my code is able to pass the test for checking numbers
But for letters in beginning it fails. Can someone please explain to me why what im doing fails to pass for letters in combination with checking for numbers.
let username = "JackOfAllTrades";
let userCheck = /^[a-z]+\d$/i; // Change this line
let result = userCheck.test(username);
1 The only numbers in the username have to be at the end. There can be zero or more of them at the end.
This condition doesn’t hold because yours only check for exactly one digit instead of zero or more.
3 Usernames have to be at least two characters long. A two-letter username can only use alphabet letter characters.
This condition doesn’t hold. How does yours check that two letter username must contain only alphabets? For example, a1 passes; but, it shouldn’t. (However, this won’t affect passing the tests, which you can read about from below link)
This challenge has some problems to get it perfectly.
What you wrote requires at least one digit at the end.
The first part of the solution, which solves most cases is this /^[a-z]{2,}[\d]*$/i
This takes at least two alphabets and optional numbers.
This can pass
Two letter username has only alphabets
Username ends with optional numbers, if username.length is at least 3
But this will fail the case where username is at least 3 characters long and begins with an alphabet followed by numbers. This is where the second part of my solution kicks in. However, this won’t affect passing the tests.