mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 04:37:30 +02:00
12 lines
477 B
Ruby
12 lines
477 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: /\A\+[0-9]{1,3}\.[0-9]{1,14}\z/,
|
|
attributes: attribute)
|
|
format_validator.validate(record)
|
|
end
|
|
end
|