Sha256: 7347ed1470a160e5d8a717c4bd8c23497de9f3ef6f85f5095af28167648ee5c9

Contents?: true

Size: 404 Bytes

Versions: 5

Compression:

Stored size: 404 Bytes

Contents

module Iz
  class PhoneNumber
    REGEX = /^(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})(?: *x(\d+))?$/

    attr_accessor :value

    def initialize(phone_number)
      self.value = phone_number
    end

    def valid?
      !!Iz::PhoneNumber.is_phone_number?(value)
    end

    def self.is_phone_number?(value)
      return false unless value
      value.to_s =~ REGEX
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
iz-0.3.1 lib/iz/phone_number.rb
iz-0.3.0 lib/iz/phone_number.rb
iz-0.2.1 lib/iz/phone_number.rb
iz-0.2.0 lib/iz/phone_number.rb
iz-0.1.0 lib/iz/phone_number.rb