class CurrencyValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) unless valid?(value, options) record.errors[attribute] << (options[:message] || I18n.t('active_validation.errors.messages.currency')) end end private def valid_format?(value, options) if options[:strict] value =~ /^\d+(\.\d{2})$/ else value =~ /^\d*+(\.\d{1,2})$/ end end def valid?(value, options) valid_format?(value, options) end end