class AlphaValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) if options[:strict] format = /^[A-Za-z]+$/i # Strict: requires no spaces to be included elsif options[:lowercase] format = /^[a-z]+$/ elsif options[:uppercase] format = /^[A-Z]+$/ else format = /^[A-Za-z ]+$/i end unless value =~ format record.errors[attribute] << (options[:message] || I18n.t('errors.messages.alpha')) end end end