2018-10-10 22:03:03 +00:00
|
|
|
---
|
|
|
|
id: 587d7db8367417b2b2512ba2
|
2021-03-15 03:20:39 +00:00
|
|
|
title: 限制可能的用户名
|
2018-10-10 22:03:03 +00:00
|
|
|
challengeType: 1
|
2020-08-04 07:14:01 +00:00
|
|
|
forumTopicId: 301363
|
2021-01-13 02:31:00 +00:00
|
|
|
dashedName: restrict-possible-usernames
|
2018-10-10 22:03:03 +00:00
|
|
|
---
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --description--
|
|
|
|
|
2021-03-15 03:20:39 +00:00
|
|
|
用户名在互联网上随处可见。 它们是用户在自己喜欢的网站上的唯一身份。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
2021-03-15 03:20:39 +00:00
|
|
|
需要检索数据库中的所有用户名。 以下是用户在创建用户名时必须遵守的一些简单规则。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
2021-03-15 03:20:39 +00:00
|
|
|
1) 用户名只能是数字字母字符。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
2021-03-15 03:20:39 +00:00
|
|
|
2) 用户名中的数字必须在最后。 数字可以有零个或多个。 用户名不能以数字开头。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
2021-03-15 03:20:39 +00:00
|
|
|
3) 用户名字母可以是小写字母和大写字母。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
2021-03-15 03:20:39 +00:00
|
|
|
4) 用户名长度必须至少为两个字符。 两位用户名只能使用字母。
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --instructions--
|
|
|
|
|
2021-03-15 03:20:39 +00:00
|
|
|
修改正则表达式 `userCheck` 以满足上面列出的约束。
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
# --hints--
|
|
|
|
|
2021-03-15 03:20:39 +00:00
|
|
|
你的正则表达式应该匹配字符串 `JACK`
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert(userCheck.test('JACK'));
|
|
|
|
```
|
|
|
|
|
2021-03-15 03:20:39 +00:00
|
|
|
你的正则表达式不应匹配字符串 `J`
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert(!userCheck.test('J'));
|
|
|
|
```
|
|
|
|
|
2021-03-15 03:20:39 +00:00
|
|
|
你的正则表达式应该匹配字符串 `Jo`
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert(userCheck.test('Jo'));
|
|
|
|
```
|
|
|
|
|
2021-03-15 03:20:39 +00:00
|
|
|
你的正则表达式应该匹配字符串 `Oceans11`
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert(userCheck.test('Oceans11'));
|
|
|
|
```
|
|
|
|
|
2021-03-15 03:20:39 +00:00
|
|
|
你的正则表达式应该匹配字符串 `RegexGuru`
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert(userCheck.test('RegexGuru'));
|
|
|
|
```
|
|
|
|
|
2021-03-15 03:20:39 +00:00
|
|
|
你的正则表达式不应匹配字符串 `007`
|
2020-12-16 07:37:30 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert(!userCheck.test('007'));
|
2018-10-10 22:03:03 +00:00
|
|
|
```
|
|
|
|
|
2021-03-15 03:20:39 +00:00
|
|
|
你的正则表达式不应匹配字符串 `9`
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
```js
|
|
|
|
assert(!userCheck.test('9'));
|
|
|
|
```
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-03-15 03:20:39 +00:00
|
|
|
你的正则表达式不应匹配字符串 `A1`
|
2018-10-10 22:03:03 +00:00
|
|
|
|
|
|
|
```js
|
2020-12-16 07:37:30 +00:00
|
|
|
assert(!userCheck.test('A1'));
|
2018-10-10 22:03:03 +00:00
|
|
|
```
|
|
|
|
|
2021-03-15 03:20:39 +00:00
|
|
|
你的正则表达式不应匹配字符串 `BadUs3rnam3`
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
```js
|
|
|
|
assert(!userCheck.test('BadUs3rnam3'));
|
|
|
|
```
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-03-15 03:20:39 +00:00
|
|
|
你的正则表达式应该匹配字符串 `Z97`
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
```js
|
|
|
|
assert(userCheck.test('Z97'));
|
|
|
|
```
|
2018-10-10 22:03:03 +00:00
|
|
|
|
2021-03-15 03:20:39 +00:00
|
|
|
你的正则表达式不应匹配字符串 `c57bT3`
|
2018-10-10 22:03:03 +00:00
|
|
|
|
|
|
|
```js
|
2020-12-16 07:37:30 +00:00
|
|
|
assert(!userCheck.test('c57bT3'));
|
2018-10-10 22:03:03 +00:00
|
|
|
```
|
2020-08-04 07:14:01 +00:00
|
|
|
|
2021-03-15 03:20:39 +00:00
|
|
|
你的正则表达式应该匹配字符串 `AB1`
|
2021-02-06 04:42:36 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
assert(userCheck.test('AB1'));
|
|
|
|
```
|
|
|
|
|
2021-03-15 03:20:39 +00:00
|
|
|
你的正则表达式不应匹配字符串 `J%4`
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert(!userCheck.test('J%4'))
|
|
|
|
```
|
|
|
|
|
2021-01-13 02:31:00 +00:00
|
|
|
# --seed--
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
```js
|
|
|
|
let username = "JackOfAllTrades";
|
|
|
|
let userCheck = /change/; // Change this line
|
|
|
|
let result = userCheck.test(username);
|
|
|
|
```
|
|
|
|
|
2020-12-16 07:37:30 +00:00
|
|
|
# --solutions--
|
|
|
|
|
2021-01-13 02:31:00 +00:00
|
|
|
```js
|
|
|
|
let username = "JackOfAllTrades";
|
|
|
|
const userCheck = /^[a-z]([0-9]{2,}|[a-z]+\d*)$/i;
|
|
|
|
let result = userCheck.test(username);
|
|
|
|
```
|