Hi guys I am stuck. I have tried different variations I believe this is my best one yet.
I have restricted numbers in the beginning, got letters only in middle, ending with a number, yet BadUs3rnam3 still get matched and some more failures, would love some tips
edit: so far this is my best variation /^\D[a-zA-Z]\d*$/; Your code so far
let username = "JackOfAllTrades";
let userCheck = /\D[a-z]\d*/i; // 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/96.0.4664.110 Safari/537.36
so I have added a caret before \D
thats what Iâve done /^\D[a-z]\d*/i;
how come it doesnât match c57bT3 now ( which is good ) but i donât understand.
\D matches anything but numbers character c = isnât a number. so why a caret changes it, shouldnât it search for anything but numbers anyway since itâs at the beginning of the regex?
edit : also if I put a $ sign at the end of my regex example /^\D[a-z]\d*$ to look for numbers at the end, now it doesnât match JACK, which makes sense JACK doesnât have numbers and should pass, so I am a bit confused what to do.
without $ jack passes, but I get numbers in the middle which again I find confusing since my regex doesnât have numbers in the middle
If I recall the requirements correctly, I believe you will want to use an âorâ operator (|) because part of the string can be either one pattern or another.
how would you read brackets inside your head?
for now for example [a-zA-Z] I read it as the string must have a char between a-z both capital and smaller letters, but what is the difference between that and a-zA-Z? that is a bit confusing to me.
I would read the square brackets as âone ofâ or âany ofâ in my head. /a-zA-Z/ would match the literal characters âa-zA-Zâ. The - symbol only indicates a range because it is in the brackets.