class Base64Validator < ActiveModel::EachValidator def validate_each(record, attribute, value) unless value =~ /^(?:[A-Za-z0-9+$]{4})*(?:[A-Za-z0-9+$]{2}==|[A-Za-z0-9+$]{3}=|[A-Za-z0-9+$]{4})$/ record.errors[attribute] << (options[:message] || I18n.t('errors.messages.base64')) end end end