Why is ^ a starting point ? and why is there a |?

Tell us what’s happening:
I tought the caret sign is for things we don’t want. Why is it a form of starting point. why is ther a | when the first half of it is already good?

Your code so far


let username = "JackOfAllTrades";
let userCheck = /change/; // Change this line
let result = userCheck.test(username);let username = "JackOfAllTrades";

let userCheck = /^[a-z][a-z]+\d*$|^[a-z]\d\d+$/i;
let result = userCheck.test(username);
console.log(result)
Code Explanation:
^ - start of input
[a-z] - first character is a letter
[a-z]+ - following characters are letters
\d*$ - input ends with 0 or more digits
| - or
^[a-z] - first character is a letter
\d\d+ - following characters are 2 or more digits
$ - end of input

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.93 Safari/537.36

Challenge: Restrict Possible Usernames

Link to the challenge:

I think that’s just in brackets, in a pattern.

Why is it a form of starting point.

They needed a character for that and they chose the caret. I don’t know why.

why is ther a | when the first half of it is already good?

The first half won’t pass all the tests. Try it and see which tests won’t pass and why.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.