IcEWaRRiOr_2002
@IcEWaRRiOr_2002

Регулярные выражения: ограничение возможных имен пользователей?

Застрял на вопросе курса freeCodeCamp:

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 lowercase and uppercase.

Usernames have to be at least two characters long. A two-character username can only use alphabet letters as characters.

Change the regex userCheck to fit the constraints listed above.

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


// running tests
Your regex should not match 007
Your regex should not match A1
Your regex should not match BadUs3rnam3
Your regex should not match c57bT3
// tests completed


☑Your regex should match JACK
☑Your regex should not match J
☑Your regex should match Jo
☑Your regex should match Oceans11
☑Your regex should match RegexGuru
☒Your regex should not match 007
☑Your regex should not match 9
☒Your regex should not match A1
☒Your regex should not match BadUs3rnam3
☑Your regex should match Z97
☒Your regex should not match c57bT3
☑Your regex should match AB1
  • Вопрос задан
  • 90 просмотров
Решения вопроса 1
/^(([A-Z]{2,}[0-9]*)|([A-Z]{1}[0-9]{2,}))$/i
2 буквы и N цифр
или одна буква и 2+ цифр
Максимально наивный вариант
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы