mirror of
https://github.com/internetee/registry.git
synced 2025-05-19 02:39:37 +02:00
Add ISO standard validators
This commit is contained in:
parent
937ce9b082
commit
dfca1d4e69
5 changed files with 60 additions and 0 deletions
13
lib/validators/iso8601_validator.rb
Normal file
13
lib/validators/iso8601_validator.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
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
|
Loading…
Add table
Add a link
Reference in a new issue