Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

UK numbers started #16

Merged
7 commits merged into from

3 participants

@kbingman

I got the basic UK numbers working, but the exceptions are not formatted correctly (see London, Cardiff and Leeds in the specs).

Can you give me a pointer? The local_special_format doesn't seem to be picked up.

Keith

@floere
Owner

Good stuff! Thanks a lot – I hope to look at it this weekend :) I'll get back to you on the special format.

@floere
Owner

Thanks again, Keith.

I've noticed that you comment and uncomment the speed specs – I've added the following to Phony, so that this is not necessary anymore:
https://github.com/floere/phony/blob/master/spec/spec_helper_extensions.rb#L6-12
(Add a file in the spec dir called "performance_ratio.rb" with the content: Phony:PerformanceRatio = 0.8, for example – it is the relative performance to my personal machine. Not the best, but a solution, I know.)

Since the landline formatting in the UK seems to be length based, I couldn't use the comfortable initializer. I'll probably add a length based splitter/formatter in the near future.

Cheers
Florian

@g1smd

Heh! The UK is a little more complex than the specs listed here. It also has 5+4 and 3+6 numbering. Some areas with 4+6 numbering have a few numbers using 4+5 within (40 areas have this). Area codes with 5 digits always share their first 4 digits with 4 digit area codes (these are "mixed" areas) so the rule ordering is important. The freefone 800 numbers can be 9 or 10 digits long. There are also 500 numbers and these always have a total of 9 digits. There are also new 3xx numbers with 10 digits.

I have forked the original phony repo and sent updates which now appear in phony 1.7.11 https://github.com/floere/phony . Thanks for your code starting things off!

I also have a separate PHP validation and formatting routine for the UK. It's at: https://github.com/g1smd/Drupal-CCK-Phone-GB

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 20, 2011
  1. @kbingman

    added belgium

    kbingman authored
  2. @kbingman
  3. @kbingman

    added speed tests back

    kbingman authored
Commits on Jan 26, 2011
  1. @kbingman
Commits on Feb 11, 2011
  1. @kbingman

    added uk

    kbingman authored
  2. @kbingman

    cleanup UK formatting

    kbingman authored
  3. @kbingman

    speed tests

    kbingman authored
This page is out of date. Refresh to see the latest.
View
1  lib/phony.rb
@@ -28,6 +28,7 @@
require File.expand_path '../phony/countries/romania', __FILE__
require File.expand_path '../phony/countries/south_korea', __FILE__
require File.expand_path '../phony/countries/sweden', __FILE__
+require File.expand_path '../phony/countries/united_kingdom', __FILE__
require File.expand_path '../phony/country_codes', __FILE__
View
2  lib/phony/countries/all_other.rb
@@ -72,7 +72,7 @@ def self.mapping
# }
),
'43' => Countries::Austria,
- '44' => fixed(2), # TODO United Kingdom of Great Britain and Northern Ireland
+ '44' => Countries::UnitedKingdom, # TODO United Kingdom of Great Britain and Northern Ireland
'45' => fixed(2, # Denmark
:local_format => [2, 2, 2],
:service_ndcs => %w{112 114}
View
87 lib/phony/countries/united_kingdom.rb
@@ -0,0 +1,87 @@
+# The United Kingdom uses a variable-length ndc code, thus we use a separate file to not let all_other.rb explode.
+#
+# Note: The United Kingdom uses a variable ndc format from length 2 to 4.
+#
+Phony::Countries::UnitedKingdom = Phony::Country.configured :local_format => [8],
+ :local_special_format => [4, 4],
+ :mobile_local_format => [6],
+ :ndc_fallback_length => 4,
+ :ndc_mapping => {
+ :landline => [
+ '20', # London
+ '23', # Southampton, Portsmith
+ '24', # Coventry
+ '28', # Northern Ireland
+ '29', # Caridff
+ '113', # Leeds
+ '114', # Sheffield
+ '115', # Nottingham
+ '116', # Leicester
+ '117', # Bristol
+ '118', # Reading
+ '121', # Birmingham
+ '131', # Edinburgh
+ '141', # Glasgow
+ '151', # Liverpool
+ '161', # Manchester
+ '171', # Used for inner London until 2000
+ '181', # Used for outer London until 2000
+ '191', # Tyne and Wear/County Durham
+ '1204', # Bolton
+ '1224', # Aberdeen
+ '1244', # Chester
+ '1382', # Dundee
+ '1429', # Hartlepool
+ '1482', # Hull
+ '1527', # Redditch
+ '1582', # Luton
+ '1670', # Morpeth
+ '1730', # Petersfield
+ '1736', # Penzance
+ '1750', # Selkirk
+ '1772', # Preston
+ '1853', # Ullapool
+ '1900', # Workington
+ '1946', # Whitehaven
+ '1947', # Whitby
+ # 5 Digit prefixes
+ '13873', # Langholm
+ '15242', # Hornby
+ '15394', # Hawkshead
+ '15395', # Grange-over-Sands
+ '15396', # Sedbergh
+ '16973', # Wigton
+ '16974', # Raughton Head
+ '16977', # Brampton[3][4]
+ '17683', # Appleby
+ '17684', # Pooley Bridge
+ '17687', # Keswick
+ '19467', # Gosforth
+
+ ],
+ :mobile => [
+ '7400',
+ '7500',
+ '7600',
+ '7700',
+ '7800',
+ '7900',
+ ],
+ :service => [
+ '800', # Freephone
+ '808', # Freephone
+ '842',
+ '843',
+ '844',
+ '845',
+ '870',
+ '871',
+ '872',
+ '873',
+ '900', # Premium rate content services
+ '908', # Sexual entertainment services
+ '909', # Sexual entertainment services
+ '982', # Sexual entertainment services
+ ]
+ }
+
View
1  spec/lib/phony/countries/belgium_spec.rb
@@ -1,5 +1,6 @@
# encoding: utf-8
#
+
require 'spec_helper'
describe Phony::Countries::Belgium do
View
50 spec/lib/phony/countries/united_kingdom_spec.rb
@@ -0,0 +1,50 @@
+require 'spec_helper'
+
+describe Phony::Countries::UnitedKingdom do
+
+ before(:each) do
+ @uk = Phony::Countries::UnitedKingdom
+ end
+
+ # Note: Many Specs
+ #
+ describe "split" do
+ it "should handle London" do
+ @uk.split('2045671113').should == ['20', '4567', '1113']
+ end
+ it "should handle Cardiff" do
+ @uk.split('2076229901').should == ['20', '7622', '9901']
+ end
+ it "should handle Leeds" do
+ @uk.split('1136770011').should == ['113', '677', '0011']
+ end
+ it "should handle Dundee" do
+ @uk.split('1382229845').should == ['1382', '229845']
+ end
+ it "should handle Bolten" do
+ @uk.split('120499532').should == ['1204', '99532']
+ end
+ it "should handle Sedbergh" do
+ @uk.split('1539618756').should ==['15396', '18756']
+ end
+ it "should handle Mobile Numbers" do
+ @uk.split('7780605207').should == ['7780', '605207']
+ end
+ it "should handle Mobile Numbers" do
+ @uk.split('7480605207').should == ['7480', '605207']
+ end
+ it "should handle service numbers with 800 [regression]" do
+ @uk.split('8005878323').should == ['800', '587', '8323']
+ end
+ #
+ # 44 116 xxx xxxx Leicester
+ # 44 131 xxx xxxx Edinburgh
+ # 44 151 xxx xxxx Liverpool
+ # 44 1382 xxxxxx Dundee
+ # 44 1386 xxxxxx Evesham
+ # 44 1865 xxxxxx Oxford
+ # 44 153 96 xxxxx Sedbergh
+ # 44 169 77 xxxx Brampton
+ end
+
+end
View
2  spec/lib/phony_spec.rb
@@ -73,7 +73,7 @@
Phony.split('51912341234').should == ['51', '9', '1234', '1234'] # mobile
Phony.split('51841234123').should == ['51', '84', '1234', '123'] # Cuzco, best effort
end
- it "should handle polish numbers" do
+ it "handles polish numbers" do
Phony.split('48123123123').should == ['48', '123', '123', '123']
end
it 'handles portuguese numbers' do
Something went wrong with that request. Please try again.