freeCodeCamp/guide/english/certifications/javascript-algorithms-and-d.../regular-expressions/restrict-possible-usernames/index.md

626 B

title
Restrict Possible Usernames

Restrict Possible Usernames

Solution:

let username = "JackOfAllTrades";
let userCheck = /^[a-z]{2,}\d*$/i;
let result = userCheck.test(username);

Explain:

  1. The only numbers in the username have to be at the end. \d$ There can be zero or more of them at the end. *
/\d*$/;
  1. Username letters can be lowercase and uppercase. i
/\d*$/i;
  1. Usernames have to be at least two characters long. {2,} A two-letter username can only use alphabet letter characters. ^[a-z]
/^[a-z]{2,}\d*$/i;