Skip to content

regexhq/regex-username

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

regex-username

NPM version build status Test coverage Downloads

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'); // => true
regex().test('foobar'); // => true
regex().test('3foobar'); // => true
regex().test('3foo-bar'); // => true
regex().test('foo-bar-baz'); // => true
regex().test('f'); // => true
regex().test('foo-bar-'); // => false
regex().test('-foo-bar'); // => false
regex().test('foo--bar'); // => false
regex().test('~derp@darp---++asdf'); // => false
regex().test('[email protected]'); // => false
regex().test('foo_bar'); // => false

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

About

Regular expression for usernames

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published