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
|
2018-09-30 23:01:58 +01:00
|
|
|
---
|
|
|
|
|
|
|
|
## Description
|
|
|
|
<section id='description'>
|
|
|
|
Usernames are used everywhere on the internet. They are what give users a unique identity on their favorite sites.
|
|
|
|
You need to check all the usernames in a database. Here are some simple rules that users have to follow when creating their username.
|
2019-04-30 18:40:38 -07:00
|
|
|
1) Usernames can only use alpha-numeric characters.
|
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.
|
2019-04-30 18:40:38 -07:00
|
|
|
3) Username letters can be lowercase and uppercase.
|
|
|
|
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
|
|
|
</section>
|
|
|
|
|
|
|
|
## Instructions
|
|
|
|
<section id='instructions'>
|
|
|
|
Change the regex <code>userCheck</code> to fit the constraints listed above.
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
```yml
|
2018-10-04 14:37:37 +01:00
|
|
|
tests:
|
|
|
|
- text: Your regex should match <code>JACK</code>
|
2019-04-30 18:40:38 -07:00
|
|
|
testString: assert(userCheck.test("JACK"));
|
2018-10-04 14:37:37 +01:00
|
|
|
- text: Your regex should not match <code>J</code>
|
2019-04-30 18:40:38 -07:00
|
|
|
testString: assert(!userCheck.test("J"));
|
2019-03-19 17:21:30 -05:00
|
|
|
- text: Your regex should match <code>Jo</code>
|
2019-04-30 18:40:38 -07:00
|
|
|
testString: assert(userCheck.test("Jo"));
|
2018-10-04 14:37:37 +01:00
|
|
|
- text: Your regex should match <code>Oceans11</code>
|
2019-04-30 18:40:38 -07:00
|
|
|
testString: assert(userCheck.test("Oceans11"));
|
2018-10-04 14:37:37 +01:00
|
|
|
- text: Your regex should match <code>RegexGuru</code>
|
2019-04-30 18:40:38 -07:00
|
|
|
testString: assert(userCheck.test("RegexGuru"));
|
2018-10-04 14:37:37 +01:00
|
|
|
- text: Your regex should not match <code>007</code>
|
2019-04-30 18:40:38 -07:00
|
|
|
testString: assert(!userCheck.test("007"));
|
2018-10-04 14:37:37 +01:00
|
|
|
- text: Your regex should not match <code>9</code>
|
2019-04-30 18:40:38 -07:00
|
|
|
testString: assert(!userCheck.test("9"));
|
2018-11-07 00:21:26 +11:00
|
|
|
- text: Your regex should not match <code>A1</code>
|
2019-04-30 18:40:38 -07:00
|
|
|
testString: assert(!userCheck.test("A1"));
|
2018-11-07 00:21:26 +11:00
|
|
|
- text: Your regex should not match <code>BadUs3rnam3</code>
|
2019-04-30 18:40:38 -07:00
|
|
|
testString: assert(!userCheck.test("BadUs3rnam3"));
|
|
|
|
- text: Your regex should match <code>Z97</code>
|
2019-11-25 17:25:24 -08:00
|
|
|
testString: assert(userCheck.test("Z97"));
|
|
|
|
- text: Your regex should not match <code>c57bT3</code>
|
|
|
|
testString: assert(!userCheck.test("c57bT3"));
|
2020-11-01 22:24:35 +09:00
|
|
|
- text: Your regex should match <code>AB1</code>
|
|
|
|
testString: assert(userCheck.test("AB1"));
|
2018-09-30 23:01:58 +01:00
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
<div id='js-seed'>
|
|
|
|
|
|
|
|
```js
|
|
|
|
let username = "JackOfAllTrades";
|
|
|
|
let userCheck = /change/; // Change this line
|
|
|
|
let result = userCheck.test(username);
|
|
|
|
```
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
<section id='solution'>
|
|
|
|
|
|
|
|
```js
|
2019-04-30 18:40:38 -07:00
|
|
|
let username = "JackOfAllTrades";
|
|
|
|
const userCheck = /^[a-z]([0-9]{2,}|[a-z]+\d*)$/i;
|
|
|
|
let result = userCheck.test(username);
|
2018-09-30 23:01:58 +01:00
|
|
|
```
|
2018-11-07 00:21:26 +11:00
|
|
|
|
2018-09-30 23:01:58 +01:00
|
|
|
</section>
|