Skip to content

GrantBirki/github-username-regex-ruby

Repository files navigation

github-username-regex-ruby

test lint build release CodeQL

A lightweight Ruby Gem to check if a GitHub username / handle is valid

Installation πŸ’Ž

You can download this Gem from either RubyGems or GitHub Packages

RubyGems (Recommended):

gem install github-username-regex-ruby

RubyGems link

Usage πŸ’»

require "github_username_regex_ruby"

# Check if a username is valid
GitHubUsernameRegex.valid?("GrantBirki") # => returns true
GitHubUsernameRegex.valid?("some$bad_username-") # => returns false

Regex βš™οΈ

The following regex pattern is used to check if a username is valid:

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

View the regex here

Release πŸš€

To release a new version of this gem, simply edit the lib/version.rb in this repo. When you commit your changes to main, a new version will be automatically released via GitHub Actions to RubyGems and GitHub Packages.

Note πŸ“

This Gem 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

Credits πŸ™

This Gem is based on the following npm package