File tree 3 files changed +7
-2
lines changed
3 files changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ regex().test('-foo-bar'); // => false
26
26
regex ().test (' foo--bar' ); // => false
27
27
regex ().test (' ~derp@darp---++asdf' ); // => false
28
28
regex ().test (' derp@mail.com' ); // => false
29
+ regex ().test (' foo_bar' ); // => false
29
30
```
30
31
31
32
## Why?
Original file line number Diff line number Diff line change 2
2
* Expose username regex, following github conventions
3
3
* like:
4
4
* _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._
6
6
*
7
7
*
8
8
* Example input:
9
9
* foo
10
10
* foo-bar
11
11
*/
12
12
module . exports = function regexUsername ( ) {
13
- return / ^ \w + - ? \w + (? ! - ) $ / ;
13
+ return / ^ [ a - z A - Z 0 - 9 ] + - ? [ a - z A - Z 0 - 9 ] + (? ! - ) $ / ;
14
14
} ;
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ describe('username regex', function() {
11
11
it ( 'should match username input' , function ( ) {
12
12
assert . equal ( regex ( ) . test ( 'foobar' ) , true ) ;
13
13
assert . equal ( regex ( ) . test ( 'foo-bar' ) , true ) ;
14
+ assert . equal ( regex ( ) . test ( 'FooBar' ) , true ) ;
14
15
} ) ;
15
16
16
17
it ( 'should catch incorrect input' , function ( ) {
@@ -20,5 +21,8 @@ describe('username regex', function() {
20
21
assert . equal ( regex ( ) . test ( 'foo-bar-' ) , false ) ;
21
22
assert . equal ( regex ( ) . test ( '3tobi--ferret' ) , false ) ;
22
23
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 ) ;
23
27
} ) ;
24
28
} ) ;
You can’t perform that action at this time.
0 commit comments