Skip to content

Commit ab57246

Browse files
committed
Disallow underscores
1 parent 141660e commit ab57246

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ regex().test('-foo-bar'); // => false
2626
regex().test('foo--bar'); // => false
2727
regex().test('~derp@darp---++asdf'); // => false
2828
regex().test('derp@mail.com'); // => false
29+
regex().test('foo_bar'); // => false
2930
```
3031

3132
## Why?

index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
* Expose username regex, following github conventions
33
* like:
44
* _Username may only contain alphanumeric characters
5-
* and only single hyphen, and cannot begin or end with hyphen._
5+
* and only single hyphens, and cannot begin or end with a hyphen._
66
*
77
*
88
* Example input:
99
* foo
1010
* foo-bar
1111
*/
1212
module.exports = function regexUsername () {
13-
return /^\w+-?\w+(?!-)$/;
13+
return /^[a-zA-Z0-9]+-?[a-zA-Z0-9]+(?!-)$/;
1414
};

test.js

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ describe('username regex', function() {
1111
it('should match username input', function() {
1212
assert.equal(regex().test('foobar'), true);
1313
assert.equal(regex().test('foo-bar'), true);
14+
assert.equal(regex().test('FooBar'), true);
1415
});
1516

1617
it('should catch incorrect input', function() {
@@ -20,5 +21,8 @@ describe('username regex', function() {
2021
assert.equal(regex().test('foo-bar-'), false);
2122
assert.equal(regex().test('3tobi--ferret'), false);
2223
assert.equal(regex().test('~~derp@darp-----++asdfasdf'), false);
24+
assert.equal(regex().test('foo_bar'), false);
25+
assert.equal(regex().test('_foobar'), false);
26+
assert.equal(regex().test('foobar_'), false);
2327
});
2428
});

0 commit comments

Comments
 (0)