Skip to content
This repository

E164 international phone number normalizing, splitting, formatting.

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 .bundle
Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.textile
Octocat-spinner-32 Rakefile
Octocat-spinner-32 history.textile
Octocat-spinner-32 phony.gemspec
README.textile

Phony

Description

This gem can normalize, format and split E164 numbers.
More about E164 numbers in this Wiki.

Currently handles Afghan, Austrian, Australian, Belgian, Brazilian, Chilean, Czech, Danish, Dutch, Egyptian, French, German, Greek, Hungarian, Italian, (The) Netherlands, New Zealand, Norwegian, Peruvian, Polish, Russian, Romanian, South African, Spanish, Swedish, Swiss, Liechtenstein, US, Venezuelan numbers.
And to some extend, all others. Just try if it works for you.

Installation

gem install phony

Some examples

Normalizing

Phony.normalize('41443643533').should == '41443643533'

Phony.normalize('+41 44 364 35 33').should == '41443643533'

Phony.normalize('+41 44 364 35 33').should == '41443643533'

Phony.normalize('+41 800 11 22 33').should == '41800112233'

Phony.normalize('John: +41 44 364 35 33').should == '41443643533'

Phony.normalize('1 (703) 451-5115').should == '17034515115'

Phony.normalize('1-888-407-4747').should == '18884074747'

Phony.normalize('1.906.387.1698').should == '19063871698'

Phony.normalize('+41 (044) 364 35 33').should == '41443643533'

Formatting

Phony.formatted('41443643532').should == '+41 44 364 35 32'

Phony.formatted('41800112233').should == '+41 800 11 22 33'

Phony.formatted('43198110').should == '+43 1 98110'

Phony.formatted('18705551122').should == '+1 870 555 1122'

International

Phony.formatted('18091231234', :format => :international).should == '+1 809 123 1234'

Phony.formatted('43198110', :format => :international).should == '+43 1 98110'

Phony.formatted('43198110', :format => :international_absolute).should == '+43 1 98110'

Phony.formatted('33142278186', :format => :+).should == '+33 1 42 27 81 86'

Phony.formatted('43198110', :format => :international_relative).should == '0043 1 98110'

Phony.formatted('4233841148', :format => :international_relative).should == '00423 384 11 48'

With spaces

Phony.formatted('18091231234', :format => :international, :spaces => '').should == '+18091231234'

Phony.formatted('43198110', :format => :international, :spaces => '').should == '+43198110'

Phony.formatted('43198110', :format => :international_absolute, :spaces => '').should == '+43198110'

Phony.formatted('33142278186', :format => :+, :spaces => '').should == '+33142278186'

Phony.formatted('43198110', :format => :international_relative, :spaces => '').should == '0043198110'

Phony.formatted('4233841148', :format => :international_relative, :spaces => '').should == '004233841148'

With special spaces

Phony.formatted('18091231234', :format => :international, :spaces => :-).should == '+1-809-123-1234'

Phony.formatted('43198110', :format => :international, :spaces => :-).should == '+43-1-98110'

Phony.formatted('43198110', :format => :international_absolute, :spaces => :-).should == '+43-1-98110'

Phony.formatted('33142278186', :format => :+, :spaces => :-).should == '+33-1-42-27-81-86'

Phony.formatted('43198110', :format => :international_relative, :spaces => :-).should == '0043-1-98110'

Phony.formatted('4233841148', :format => :international_relative, :spaces => :-).should == '00423-384-11-48'

National

Phony.formatted('41443643532', :format => :national).should == '044 364 35 32'

Phony.formatted('41800112233', :format => :national).should == '0800 11 22 33'

Phony.formatted('43198110', :format => :national).should == '01 98110'

Local

Phony.formatted('41443643532', :format => :local).should == '364 35 32'

Phony.formatted('493038625454', :format => :local).should == '386 25454'

Splitting

Phony.split('43198110').should == ['43', '1', '98110']

Phony.split('33112345678').should == ['33', '1', '12','34','56','78']

Phony.split('4976112345').should == ['49', '761', '123', '45']

Phony.split('3928061371').should == ['39', '2', '806', '1371']

Phony.split('41443643532').should == ['41', '44', '364', '35', '32']

Phony.split('15551115511').should == ['1', '555', '111', '5511']

Phony.split('6491234567').should == ['64', '9', '123', '4567']

Phony.split('41800334455').should == ['41', '800', '33', '44', '55']

Note: There is also a ! version of each of these methods which
will destroy the original string and return a new (or old) one.
Just work only with the returned value, and you will be fine.

Something went wrong with that request. Please try again.