|
4 | 4 | [![Test coverage][coveralls-image]][coveralls-url]
|
5 | 5 | [![Downloads][downloads-image]][downloads-url]
|
6 | 6 |
|
7 |
| -Regular expression for usernames. |
| 7 | +Regular expression for usernames - it follows the same rules that GitHub uses. |
8 | 8 |
|
9 | 9 | ## Installation
|
10 |
| -```bash |
| 10 | + |
| 11 | +```sh |
11 | 12 | npm install regex-username
|
12 | 13 | ```
|
13 | 14 |
|
14 | 15 | ## Usage
|
| 16 | + |
15 | 17 | ```js
|
16 | 18 | var regex = require('regex-username');
|
17 | 19 |
|
18 |
| -regex().test('tobi-ferret'); |
19 |
| -// => true |
| 20 | +regex().test('foo-bar'); // => true |
| 21 | +regex().test('foobar'); // => true |
| 22 | +regex().test('3foobar'); // => true |
| 23 | +regex().test('3foo-bar'); // => true |
| 24 | +regex().test('foo-bar-'); // => false |
| 25 | +regex().test('-foo-bar'); // => false |
| 26 | +regex().test('foo--bar'); // => false |
| 27 | +regex().test('~derp@darp---++asdf'); // => false |
| 28 | +regex(). test( '[email protected]'); // => false |
20 | 29 | ```
|
21 | 30 |
|
22 | 31 | ## Why?
|
23 | 32 | Which usernames to allow typically varies between applications. For prototypes
|
24 | 33 | however it's nice to have an off the shelf solution. This module is that
|
25 | 34 | solution. It follows the same rules GitHub uses:
|
26 |
| -> Username may only contain alphanumeric characters or dashes and cannot begin |
27 |
| -with a dash |
| 35 | + |
| 36 | +> Username may only contain alphanumeric characters or single hyphens, and cannot begin or end with a hyphen. |
28 | 37 |
|
29 | 38 | ## See Also
|
30 |
| -- [regex-email](https://github.com/regexps/email) |
| 39 | +- [regex-email](https://github.com/regexhq/regex-email) |
| 40 | +- [youtube-regex](https://github.com/regexhq/youtube-regex) |
31 | 41 |
|
32 | 42 | ## License
|
33 | 43 | [MIT](https://tldrlegal.com/license/mit-license)
|
34 | 44 |
|
35 | 45 | [npm-image]: https://img.shields.io/npm/v/regex-username.svg?style=flat-square
|
36 |
| -[npm-url]: https://npmjs.org/package/regex-username |
37 |
| -[travis-image]: https://img.shields.io/travis/regexps/regex-username.svg?style=flat-square |
38 |
| -[travis-url]: https://travis-ci.org/regexps/regex-username |
39 |
| -[coveralls-image]: https://img.shields.io/coveralls/regexps/regex-username.svg?style=flat-square |
40 |
| -[coveralls-url]: https://coveralls.io/r/regexps/regex-username?branch=master |
| 46 | +[npm-url]: https://www.npmjs.com/package/regex-username |
| 47 | +[travis-image]: https://img.shields.io/travis/regexhq/regex-username.svg?style=flat-square |
| 48 | +[travis-url]: https://travis-ci.org/regexhq/regex-username |
| 49 | +[coveralls-image]: https://img.shields.io/coveralls/regexhq/regex-username.svg?style=flat-square |
| 50 | +[coveralls-url]: https://coveralls.io/r/regexhq/regex-username?branch=master |
41 | 51 | [downloads-image]: http://img.shields.io/npm/dm/regex-username.svg?style=flat-square
|
42 | 52 | [downloads-url]: https://npmjs.org/package/regex-username
|
0 commit comments