From A - Z letters and you can only use usernames from 2 characters.
not really… [A-Z]{2,}
means “two or more letters”, just that
Does “Z97” start with two or more letters?
No, it does not. It is only a letter and two numbers.
So it’s not going to match your pattern.
I will try it again.
Good morning, this code says that the first letter has to be a capital letter and the last one can be numbers and letters. How can I set the first one and the last one must be letters in the case of an username of two letters to pass the tests
/^[A-Z][A-Z0-9]{1,10}$/i
I am trying with this code with the examples in test ^[A-Za-z]+[0-9]{0,}$ and I am not getting passed. But, I use them in RegEx and I am getting them match.
What is your complete current code?
let username = "JackOfAllTrades";
let userCheck = /^[A-Za-z]+[A-Za-z]+[0-9]{0,}$/gi; // Change this line
let result = userCheck.test(username);
console.log(result);
-
the
g
flag is going to cause tests to fail. Learn why by researching the global search flag. You can start here:
https://stackoverflow.com/questions/1520800/why-does-a-regexp-with-global-flag-give-wrong-results -
Your pattern requires that all usernames must start with at least two letters, but “Z97” is a valid username.
-
If you are including both upper and lower case with
[A-Za-z]
then you don’t need thei
flag, and vice versa.
I tried this with RegExr and It worked with the cases, but I am trying in here and It is not getting passed. Is it a bug?
^[A-Z]([A-Z]+|[0-9]{2,})[0-9]*$/gi
Are you still using the global flag?
I will read the article. Thanks!
Thanks for your help!
^[A-Z]([A-Z]+|[0-9]{2,})[0-9]*$/i
Congratulations! Happy coding.