Sha256: ac2a809700a9dd1dc134d975a120bf06c29ff81a55794880a9b0b909b7a7ba42
Contents?: true
Size: 578 Bytes
Versions: 4
Compression:
Stored size: 578 Bytes
Contents
class CurrencyValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) unless valid?(value.to_s, options) record.errors[attribute] << (options.fetch(:message, false) || I18n.t('active_validation.errors.messages.currency'.freeze)) end end private def valid_format?(value, options) value =~ (options.fetch(:strict, false) ? /^\d+(\.\d{2})$/ : /^\d*+(\.\d{1,2})$/) end def valid_length?(value) value.present? end def valid?(value, options) valid_length?(value) && valid_format?(value, options) end end
Version data entries
4 entries across 4 versions & 1 rubygems