Skip to content

Commit

Permalink
Merge pull request floere#162 from dom1nga/master
Browse files Browse the repository at this point in the history
6 and 8 digit mobile number support for NZ (+64)
  • Loading branch information
floere committed May 26, 2014
2 parents 91b13be + 73d127c commit 3698208
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/phony/countries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,10 @@
# New Zealand.
#
country '64',
match(/^(2\d)\d+$/) >> split(3,4) | # Mobile
fixed(1) >> split(3,4) # Rest
match(/^(2\d)\d{7}$/) >> split(3,4) | # Mobile
match(/^(2\d)\d{6}$/) >> split(3,3) |
match(/^(2\d)\d{8}$/) >> split(2,3,3) |
fixed(1) >> split(3,4) # Rest

# Singapore (Republic of).
#
Expand Down
9 changes: 9 additions & 0 deletions spec/functional/plausibility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,15 @@ def self.it_is_correct_for(country_name, options={})
Phony.plausible?('+599 12345678').should be_false # too long
end

it 'is correct for New Zeland' do
Phony.plausible?('+64 21 123 456').should be_true
Phony.plausible?('+64 21 123 4567').should be_true
Phony.plausible?('+64 9 379 1234').should be_true
Phony.plausible?('+64 21 12 345 678').should be_true
Phony.plausible?('+64 21 1234 56789').should be_false # to long
Phony.plausible?('+64 21 12345').should be_false # to short
end

it 'is correct for Nigerian numbers' do
Phony.plausible?('+234 807 766 1234').should be_true
Phony.plausible?('+234 807 766 123').should be_false
Expand Down
8 changes: 7 additions & 1 deletion spec/lib/phony_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,15 @@
it 'should format american numbers' do
Phony.format('18705551122').should eql '+1 870 555 1122'
end
it 'should format New Zealand 021 mobile numbers' do
it 'should format New Zealand 021 6-digit mobile numbers' do
Phony.format('6421123456').should eql '+64 21 123 456'
end
it 'should format New Zealand 021 7-digit mobile numbers' do
Phony.format('64211234567').should eql '+64 21 123 4567'
end
it 'should format New Zealand 021 8-digit mobile numbers' do
Phony.format('642112345678').should eql '+64 21 12 345 678'
end
it 'should format New Zealand landline numbers' do
Phony.format('6493791234').should eql '+64 9 379 1234'
end
Expand Down

0 comments on commit 3698208

Please sign in to comment.