A lightweight Ruby Gem to check if a GitHub username / handle is valid
You can download this Gem from either RubyGems or GitHub Packages
RubyGems (Recommended):
gem install github-username-regex-ruby
RubyGems link
require "github_username_regex_ruby"
# Check if a username is valid
GitHubUsernameRegex.valid?("GrantBirki") # => returns true
GitHubUsernameRegex.valid?("some$bad_username-") # => returns false
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
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.
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
This Gem is based on the following npm package