https://github.com/grantbirki/github-username-regex-ruby
A lightweight Ruby Gem to check if a GitHub username / handle is valid
https://github.com/grantbirki/github-username-regex-ruby
gem github regex ruby validation
Last synced: 9 months ago
JSON representation
A lightweight Ruby Gem to check if a GitHub username / handle is valid
- Host: GitHub
- URL: https://github.com/grantbirki/github-username-regex-ruby
- Owner: GrantBirki
- License: mit
- Created: 2023-06-24T18:13:07.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-01-14T21:57:41.000Z (over 1 year ago)
- Last Synced: 2025-01-20T16:54:52.333Z (over 1 year ago)
- Topics: gem, github, regex, ruby, validation
- Language: Ruby
- Homepage: https://rubygems.org/gems/github-username-regex-ruby
- Size: 27.2 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# github-username-regex-ruby
[](https://github.com/GrantBirki/github-username-regex-ruby/actions/workflows/test.yml) [](https://github.com/GrantBirki/github-username-regex-ruby/actions/workflows/lint.yml) [](https://github.com/GrantBirki/github-username-regex-ruby/actions/workflows/build.yml) [](https://github.com/GrantBirki/github-username-regex-ruby/actions/workflows/release.yml) [](https://github.com/GrantBirki/github-username-regex-ruby/actions/workflows/codeql-analysis.yml)
A lightweight Ruby Gem to check if a GitHub username / handle is valid
## Installation 💎
You can download this Gem from either [RubyGems](https://rubygems.org/gems/github-username-regex-ruby) or [GitHub Packages](https://github.com/GrantBirki/github-username-regex-ruby/pkgs/rubygems/github-username-regex-ruby)
RubyGems (Recommended):
```bash
gem install github-username-regex-ruby
```
> RubyGems [link](https://rubygems.org/gems/github-username-regex-ruby)
## Usage 💻
```ruby
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:
```re
/^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$/i
```
> View the regex [here](lib/github_username_regex_ruby.rb)
## Release 🚀
To release a new version of this gem, simply edit the [`lib/version.rb`](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](https://github.com/shinnn/github-username-regex)