mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 09:27:19 +02:00
12 lines
474 B
Ruby
12 lines
474 B
Ruby
class E164Validator < ActiveModel::EachValidator
|
|
def validate_each(record, attribute, _value)
|
|
length_validator = ActiveModel::Validations::
|
|
LengthValidator.new(maximum: 17, attributes: attribute)
|
|
length_validator.validate(record)
|
|
|
|
format_validator = ActiveModel::Validations::
|
|
FormatValidator.new(with: /\+[0-9]{1,3}\.[0-9]{1,14}?/,
|
|
attributes: attribute)
|
|
format_validator.validate(record)
|
|
end
|
|
end
|