Class: TextBelt::PhoneValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/textbelt/validators/phone_validator.rb

Overview

Validator for outgoing phone numbers

Author:

  • Dean Silfen

Class Method Summary collapse

Class Method Details

.validate(phone_number, country) ⇒ Boolean

Get a list of categories from the service

Parameters:

  • phone_number (String)

    number to send the text to

  • country (String)

    ISO 3166 Country code for destination country

Returns:

  • (Boolean)

    true if TextBelt successfully passed on the message, false if not

Raises:



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/textbelt/validators/phone_validator.rb', line 20

def validate(phone_number, country)
  unless  is_a_string?(phone_number)
    raise TextBelt::Errors::IntegerPhoneError, "Please ensure to pass phone numbers as strings."
  end

  phone = Phonelib.parse phone_number

  if phone.impossible?
    raise TextBelt::Errors::InvalidPhoneNumberError, "#{phone_number} is not valid in destination country #{country}"
  end
end