class DefraRuby::Validators::PhoneNumberValidator

Constants

MAX_LENGTH

Public Instance Methods

validate_each(record, attribute, value) click to toggle source
# File lib/defra_ruby/validators/phone_number_validator.rb, line 13
def validate_each(record, attribute, value)
  return false unless value_is_present?(record, attribute, value)
  return false unless value_is_not_too_long?(record, attribute, value, MAX_LENGTH)

  valid_format?(record, attribute, value)
end

Private Instance Methods

valid_format?(record, attribute, value) click to toggle source
# File lib/defra_ruby/validators/phone_number_validator.rb, line 22
def valid_format?(record, attribute, value)
  Phonelib.default_country = "GB"
  return true if Phonelib.valid?(value)

  add_validation_error(record, attribute, :invalid_format)
  false
end