Skip to content
A regular expression that only matches a currently valid Github username
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.editorconfig init Jan 18, 2017
.gitattributes init Jan 18, 2017
.gitignore init Jan 18, 2017
.travis.yml init Jan 18, 2017
README.md init Jan 18, 2017
bower.json init Jan 18, 2017
index.js init Jan 18, 2017
module.js init Jan 18, 2017
package.json init Jan 18, 2017
test.js init Jan 18, 2017

README.md

github-username-regex

NPM version Bower version Build Status

A regular expression that only matches a valid Github username

import githubUsernameRegex from 'github-username-regex';

githubUsernameRegex.test('john'); //=> true
githubUsernameRegex.test('john-due'); //=> true
githubUsernameRegex.test('john-due-'); //=> false

According to the form validation messages on Join Github page,

  • Github username may only contain alphanumeric characters or hyphens.
  • Github username cannot have multiple consecutive hyphens.
  • Github username cannot begin or end with a hyphen.
  • Maximum is 39 characters.

Installation

npm

npm install github-username-regex

bower

bower install github-username-regex

API

import githubUsernameRegex from 'github-username-regex';

githubUsernameRegex

Type: RegExp (/^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i)

// Returns `true`
githubUsernameRegex.test('a');
githubUsernameRegex.test('0');
githubUsernameRegex.test('a-b');
githubUsernameRegex.test('a-b-123');
githubUsernameRegex.test('a'.repeat(39));

// Returns `false`
githubUsernameRegex.test('');
githubUsernameRegex.test('a_b');
githubUsernameRegex.test('a--b');
githubUsernameRegex.test('a-b-');
githubUsernameRegex.test('-a-b');
githubUsernameRegex.test('a'.repeat(40));

Note that this module doesn't take reserved usernames into consideration. For example it matches help, about and pricing, though they are reserved words and cannot be used as Github usernames.

License

Creative Commons Zero v1.0 Universal

You can’t perform that action at this time.