Class: UsernameFormatValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/generators/authkit/templates/lib/username_format_validator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.is_valid_username(value) ⇒ Object



8
9
10
# File 'lib/generators/authkit/templates/lib/username_format_validator.rb', line 8

def self.is_valid_username(value)
  value =~ /\A[0-9A-Za-z\-\_]+\z/
end

Instance Method Details

#validate_each(object, attribute, value) ⇒ Object



2
3
4
5
6
# File 'lib/generators/authkit/templates/lib/username_format_validator.rb', line 2

def validate_each(object, attribute, value)
  unless UsernameFormatValidator::is_valid_username(value)
    object.errors[attribute] << (options[:message] || "is not a valid username")
  end
end