Files

2.6 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
587d7db8367417b2b2512ba2 限制可能的用戶名 1 301363 restrict-possible-usernames

--description--

用戶名在互聯網上隨處可見。 它們是用戶在自己喜歡的網站上的唯一身份。

需要檢索數據庫中的所有用戶名。 以下是用戶在創建用戶名時必須遵守的一些簡單規則。

  1. 用戶名只能是數字字母字符。

  2. 用戶名中的數字必須在最後。 數字可以有零個或多個。 用戶名不能以數字開頭。

  3. 用戶名字母可以是小寫字母和大寫字母。

  4. 用戶名長度必須至少爲兩個字符。 兩位用戶名只能使用字母。

--instructions--

修改正則表達式 userCheck 以滿足上面列出的約束。

--hints--

你的正則表達式應該匹配字符串 JACK

userCheck.lastIndex = 0;
assert(userCheck.test('JACK'));

你的正則表達式不應匹配字符串 J

userCheck.lastIndex = 0;
assert(!userCheck.test('J'));

你的正則表達式應該匹配字符串 Jo

userCheck.lastIndex = 0;
assert(userCheck.test('Jo'));

你的正則表達式應該匹配字符串 Oceans11

userCheck.lastIndex = 0;
assert(userCheck.test('Oceans11'));

你的正則表達式應該匹配字符串 RegexGuru

userCheck.lastIndex = 0;
assert(userCheck.test('RegexGuru'));

你的正則表達式不應匹配字符串 007

userCheck.lastIndex = 0;
assert(!userCheck.test('007'));

你的正則表達式不應匹配字符串 9

userCheck.lastIndex = 0;
assert(!userCheck.test('9'));

你的正則表達式不應匹配字符串 A1

userCheck.lastIndex = 0;
assert(!userCheck.test('A1'));

你的正則表達式不應匹配字符串 BadUs3rnam3

userCheck.lastIndex = 0;
assert(!userCheck.test('BadUs3rnam3'));

你的正則表達式應該匹配字符串 Z97

userCheck.lastIndex = 0;
assert(userCheck.test('Z97'));

你的正則表達式不應匹配字符串 c57bT3

userCheck.lastIndex = 0;
assert(!userCheck.test('c57bT3'));

你的正則表達式應該匹配字符串 AB1

userCheck.lastIndex = 0;
assert(userCheck.test('AB1'));

你的正則表達式不應匹配字符串 J%4

userCheck.lastIndex = 0;
assert(!userCheck.test('J%4'))

--seed--

--seed-contents--

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

--solutions--

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