mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
13 lines
284 B
Ruby
13 lines
284 B
Ruby
class Iso8601Validator < ActiveModel::EachValidator
|
|
def validate_each(record, attribute, value)
|
|
if options[:date_only]
|
|
record.errors.add(attribute, :invalid_iso8601) unless value =~ date_format
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def date_format
|
|
/\d{4}-\d{2}-\d{2}/
|
|
end
|
|
end
|