I’m not able to pass certain test cases.
Your regex should match the string JACK
Failed:Your regex should not match the string J
Passed:Your regex should match the string Jo
Passed:Your regex should match the string Oceans11
Passed:Your regex should match the string RegexGuru
Passed:Your regex should not match the string 007
Passed:Your regex should not match the string 9
Failed:Your regex should not match the string A1
Passed:Your regex should not match the string BadUs3rnam3
Passed:Your regex should match the string Z97
Passed:Your regex should not match the string c57bT3
Passed:Your regex should match the string AB1
Passed:Your regex should not match the string J%4
The requirements for the question is stated below:-
You need to check all the usernames in a database. Here are some simple rules that users have to follow when creating their username.
Usernames can only use alpha-numeric characters.
The only numbers in the username have to be at the end. There can be zero or more of them at the end. Username cannot start with the number.
Username letters can be both lowercase and uppercase.
Usernames must be at least two characters long, and a two-character username can only contain alphabet letters.
Adjust the regex userCheck to meet the constraints listed above.
Here is the default template provided for editing:
let username = "JackOfAllTrades"; let userCheck = /change/; // Change this line let result = userCheck.test(username);
When I attempt to write the code as follows:
let userCheck = /^[A-Za-z][A-Za-z]+d*$/
it results in the following errors:
- Your regex should match the string JACK
- Failed: Your regex should not match the string J
- Passed: Your regex should match the string Jo
- Passed: Your regex should match the string Oceans11
- Passed: Your regex should match the string RegexGuru
- Passed: Your regex should not match the string 007
- Passed: Your regex should not match the string 9
- Failed: Your regex should not match the string A1
- Passed: Your regex should not match the string BadUs3rnam3
- Passed: Your regex should match the string Z97
- Passed: Your regex should not match the string c57bT3
- Passed: Your regex should match the string AB1
- Passed: Your regex should not match the string J%4
Despite asking both Copilot and ChatGPT, none of the provided answers pass all the test cases.