GithubHelp home page GithubHelp logo

shinnn / github-username-regex Goto Github PK

View Code? Open in Web Editor NEW
74.0 3.0 8.0 2 KB

A regular expression that only matches a currently valid Github username

JavaScript 100.00%
regular-expression validation account username javascript

github-username-regex's Introduction

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 install github-username-regex
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

github-username-regex's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

github-username-regex's Issues

Golang syntax

Hi there,
Do you have your regex in Golang syntax ?
Thank's a lot :-)

Does not match trailing dash

Quite surprisingly a trailing dash is allowed on GitHub... I'm not sure if this is a new thing or perhaps it's legacy and they no longer support it, but there are users out there with trailing dashes in their username, eg: https://github.com/Guin-

I'm not sure if this is something that you want to support or not

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.