No commit activity in last 3 years
No release in over 3 years
validates that username is not included in reserved list.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

UsernameNotReservedValidator

Build Status Coverage Status Code Climate

Custom validator for ActiveModel.

Validates that username is not included in the list of reserved names.

e.g:

  • index
  • home
  • top
  • ...

Installation

Add this line to your application's Gemfile:

gem 'username_not_reserved_validator'

And then execute:

$ bundle

Or install it yourself as:

$ gem install username_not_reserved_validator

Usage

validation settings

Add validation setting on your ActiveModel.

class User < ActiveRecord::Base
  validates(:name, username_not_reserved: true)
end

options

  • additional_reserved_names (Array of String / default: [])
  • specify additional reserved names
  • case_insensitive (Boolean / default: true)
  • if set to false, comparison is case sencitive
  • also key case_insencitive will be accepted due to historical typo
  • message (Symbol / default: :invalid)
  • specify custom key of error message

e.g.)

class User < ActiveRecord::Base
  validates(:name,
            username_not_reserved: {
              additional_reserved_names: %w[foo bar],
              case_insensitive: true,
              message: :reserved_username
            }
           )
end

Referenced resources

With tons of thanks 🍣