Add ISO 8601 validations

This commit is contained in:
Martin Lensment 2014-12-22 13:54:20 +02:00
parent b5bf21b127
commit 2ac59e68ff
10 changed files with 104 additions and 4 deletions

View file

@ -0,0 +1,9 @@
class DurationIso8601Validator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return unless value.present?
ISO8601::Duration.new(value)
rescue => _e
record.errors[attribute] << (options[:message] || record.errors.generate_message(attribute, :unknown_pattern))
end
end