class NameValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) unless value =~ /\A([a-zA-Z'-]+\s+){1,4}[a-zA-Z'-]*\z/i record.errors[attribute] << (options[:message] || I18n.t('yukonisuru.errors.messages.name')) end end end