2018-09-30 23:01:58 +01:00
|
|
|
---
|
|
|
|
id: 587d7db8367417b2b2512ba2
|
|
|
|
title: Restrict Possible Usernames
|
|
|
|
challengeType: 1
|
|
|
|
---
|
|
|
|
|
|
|
|
## 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.
|
|
|
|
1) The only numbers in the username have to be at the end. There can be zero or more of them at the end.
|
|
|
|
2) Username letters can be lowercase and uppercase.
|
|
|
|
3) Usernames have to be at least two characters long. A two-letter username can only use alphabet letter characters.
|
|
|
|
</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>
|
2018-10-20 21:02:47 +03:00
|
|
|
testString: assert(userCheck.test("JACK"), 'Your regex should match <code>JACK</code>');
|
2018-10-04 14:37:37 +01:00
|
|
|
- text: Your regex should not match <code>J</code>
|
2018-10-20 21:02:47 +03:00
|
|
|
testString: assert(!userCheck.test("J"), 'Your regex should not match <code>J</code>');
|
2018-10-04 14:37:37 +01:00
|
|
|
- text: Your regex should match <code>Oceans11</code>
|
2018-10-20 21:02:47 +03:00
|
|
|
testString: assert(userCheck.test("Oceans11"), 'Your regex should match <code>Oceans11</code>');
|
2018-10-04 14:37:37 +01:00
|
|
|
- text: Your regex should match <code>RegexGuru</code>
|
2018-10-20 21:02:47 +03:00
|
|
|
testString: assert(userCheck.test("RegexGuru"), 'Your regex should match <code>RegexGuru</code>');
|
2018-10-04 14:37:37 +01:00
|
|
|
- text: Your regex should not match <code>007</code>
|
2018-10-20 21:02:47 +03:00
|
|
|
testString: assert(!userCheck.test("007"), 'Your regex should not match <code>007</code>');
|
2018-10-04 14:37:37 +01:00
|
|
|
- text: Your regex should not match <code>9</code>
|
2018-10-20 21:02:47 +03:00
|
|
|
testString: assert(!userCheck.test("9"), 'Your regex should not match <code>9</code>');
|
2018-11-07 00:21:26 +11:00
|
|
|
- text: Your regex should not match <code>A1</code>
|
|
|
|
testString: assert(!userCheck.test("A1"), 'Your regex should not match <code>A1</code>');
|
|
|
|
- text: Your regex should not match <code>BadUs3rnam3</code>
|
|
|
|
testString: assert(!userCheck.test("BadUs3rnam3"), 'Your regex should not match <code>BadUs3rnam3</code>');
|
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
|
2018-11-07 00:21:26 +11:00
|
|
|
const userCheck = /^[A-Za-z]{2,}\d*$/;
|
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>
|