Class: DiscordValidator

Inherits:
AccountNameValidator show all
Defined in:
lib/discord_validator.rb

Overview

Validates Discord usernames using the modern (post-2023) username format. Discord eliminated the four-digit #1234 discriminator system in 2023; usernames are now globally unique and use the rules below:

  • 2-32 characters long
  • Lowercase letters (a-z), digits (0-9), underscore (_), and period (.)
  • No consecutive periods (..)
  • Cannot start or end with a period

The following error message keys are used to localize invalid usernames:

discord_too_short Username is less than 2 characters.
discord_too_long Username is over 32 characters.
discord_invalid_chars Username contains characters outside [a-z0-9._].
discord_invalid_format Username has consecutive periods or starts/ends with a period.

Options

:message A custom message to use if the username is invalid.
:allow_nil If true, nil values are allowed.

Examples:

validates :discord, discord: true

Method Summary

Methods inherited from AccountNameValidator

add_validation, error_key_prefix, first_char, max_length, min_length, valid_chars