regex-username

Regular expression for usernames - it follows the same rules that GitHub uses.
Installation
npm install regex-username
Usage
var regex = require('regex-username');
regex().test('foo-bar');
regex().test('foobar');
regex().test('3foobar');
regex().test('3foo-bar');
regex().test('foo-bar-');
regex().test('-foo-bar');
regex().test('foo--bar');
regex().test('~derp@darp---++asdf');
regex().test('derp@mail.com');
Why?
Which usernames to allow typically varies between applications. For prototypes
however it's nice to have an off the shelf solution. This module is that
solution. It follows the same rules GitHub uses:
Username may only contain alphanumeric characters or single hyphens, and cannot begin or end with a hyphen.
See Also
License
MIT