2018-09-30 23:01:58 +01:00
|
|
|
---
|
|
|
|
id: 587d7db8367417b2b2512ba2
|
|
|
|
title: Restrict Possible Usernames
|
|
|
|
challengeType: 1
|
2019-08-05 09:17:33 -07:00
|
|
|
forumTopicId: 301363
|
2021-01-13 03:31:00 +01:00
|
|
|
dashedName: restrict-possible-usernames
|
2018-09-30 23:01:58 +01:00
|
|
|
---
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --description--
|
|
|
|
|
2018-09-30 23:01:58 +01:00
|
|
|
Usernames are used everywhere on the internet. They are what give users a unique identity on their favorite sites.
|
2020-11-27 19:02:05 +01:00
|
|
|
|
2018-09-30 23:01:58 +01:00
|
|
|
You need to check all the usernames in a database. Here are some simple rules that users have to follow when creating their username.
|
2020-11-27 19:02:05 +01:00
|
|
|
|
2019-04-30 18:40:38 -07:00
|
|
|
1) Usernames can only use alpha-numeric characters.
|
2020-11-27 19:02:05 +01:00
|
|
|
|
2020-02-18 19:43:34 +01:00
|
|
|
2) 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.
|
2020-11-27 19:02:05 +01:00
|
|
|
|
2019-04-30 18:40:38 -07:00
|
|
|
3) Username letters can be lowercase and uppercase.
|
2020-11-27 19:02:05 +01:00
|
|
|
|
2019-04-30 18:40:38 -07:00
|
|
|
4) Usernames have to be at least two characters long. A two-character username can only use alphabet letters as characters.
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --instructions--
|
|
|
|
|
|
|
|
Change the regex `userCheck` to fit the constraints listed above.
|
|
|
|
|
|
|
|
# --hints--
|
|
|
|
|
|
|
|
Your regex should match `JACK`
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert(userCheck.test('JACK'));
|
2018-09-30 23:01:58 +01:00
|
|
|
```
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
Your regex should not match `J`
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
```js
|
|
|
|
assert(!userCheck.test('J'));
|
|
|
|
```
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
Your regex should match `Jo`
|
2018-09-30 23:01:58 +01:00
|
|
|
|
|
|
|
```js
|
2020-11-27 19:02:05 +01:00
|
|
|
assert(userCheck.test('Jo'));
|
|
|
|
```
|
|
|
|
|
|
|
|
Your regex should match `Oceans11`
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert(userCheck.test('Oceans11'));
|
|
|
|
```
|
|
|
|
|
|
|
|
Your regex should match `RegexGuru`
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert(userCheck.test('RegexGuru'));
|
2018-09-30 23:01:58 +01:00
|
|
|
```
|
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
Your regex should not match `007`
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
```js
|
|
|
|
assert(!userCheck.test('007'));
|
|
|
|
```
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
Your regex should not match `9`
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
```js
|
|
|
|
assert(!userCheck.test('9'));
|
|
|
|
```
|
2018-09-30 23:01:58 +01:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
Your regex should not match `A1`
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert(!userCheck.test('A1'));
|
|
|
|
```
|
|
|
|
|
|
|
|
Your regex should not match `BadUs3rnam3`
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert(!userCheck.test('BadUs3rnam3'));
|
|
|
|
```
|
|
|
|
|
|
|
|
Your regex should match `Z97`
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert(userCheck.test('Z97'));
|
|
|
|
```
|
|
|
|
|
|
|
|
Your regex should not match `c57bT3`
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert(!userCheck.test('c57bT3'));
|
|
|
|
```
|
|
|
|
|
|
|
|
Your regex should match `AB1`
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert(userCheck.test('AB1'));
|
|
|
|
```
|
|
|
|
|
|
|
|
# --seed--
|
|
|
|
|
|
|
|
## --seed-contents--
|
2018-09-30 23:01:58 +01:00
|
|
|
|
|
|
|
```js
|
2019-04-30 18:40:38 -07:00
|
|
|
let username = "JackOfAllTrades";
|
2020-11-27 19:02:05 +01:00
|
|
|
let userCheck = /change/; // Change this line
|
2019-04-30 18:40:38 -07:00
|
|
|
let result = userCheck.test(username);
|
2018-09-30 23:01:58 +01:00
|
|
|
```
|
2018-11-07 00:21:26 +11:00
|
|
|
|
2020-11-27 19:02:05 +01:00
|
|
|
# --solutions--
|
|
|
|
|
|
|
|
```js
|
|
|
|
let username = "JackOfAllTrades";
|
|
|
|
const userCheck = /^[a-z]([0-9]{2,}|[a-z]+\d*)$/i;
|
|
|
|
let result = userCheck.test(username);
|
|
|
|
```
|