Sha256: 30948a8e387cdf377f6bbb02bb6d8428ad2c1fe8b642e2cdcceb7ddb63d49319
Contents?: true
Size: 490 Bytes
Versions: 4
Compression:
Stored size: 490 Bytes
Contents
class UsernameValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) unless valid?(value.to_s) record.errors[attribute] << (options.fetch(:message, false) || I18n.t('active_validation.errors.messages.username'.freeze)) end end private def valid_format?(value) value =~ /^[a-z0-9_-]{2,16}$/ end def valid_length?(value) value.present? end def valid?(value) valid_length?(value) && valid_format?(value) end end
Version data entries
4 entries across 4 versions & 1 rubygems