Permalink
Browse files

+ added Israel

  • Loading branch information...
1 parent c9348ba commit f40cd6b021ca3490373f655d362f2d34fb004a6b @jcfischer jcfischer committed with Mar 14, 2013
Showing with 41 additions and 4 deletions.
  1. +1 −1 README.textile
  2. +15 −2 lib/phony/countries.rb
  3. +20 −0 spec/lib/phony/countries_spec.rb
  4. +5 −1 spec/lib/phony/validations_spec.rb
View
@@ -13,7 +13,7 @@ This gem can normalize, format and split E164 numbers.
The (admittedly crazy) *goal* of this Gem is to be able to format/split all phone numbers in the world.
-Currently handles Abhas, Afghan, Algerian, Argentinan, Austrian, Australian, Belgian, Brazilian, Cambodian, Chilean, Chinese, Croatian, Cuban, Cypriot, Czech, Danish, Dutch, Egyptian, El Salvadorian, Estonian, French, German, Ghanan, Gibraltar, Greek, Haiti, Hong Kong, Hungarian, Indian, Italian, Iran, Irish, Kazakh, Lithuanian, Luxembourgian, Malaysian, Malta, Mexican, Monaco, Morocco, New Zealand, Nigerian, Norwegian, Peruvian, Polish, Romanian, Russian, Rwandan, Seychelles, Singapore, Slovakian, South African, South Korean, South Osetian, Spanish, Sri Lankan, Sudan, Swedish, Swiss, Thailand, Tunisian, Turkish, Liechtenstein, UK, US, Venezuelan, and Vietnamese numbers.
+Currently handles Abhas, Afghan, Algerian, Argentinan, Austrian, Australian, Belgian, Brazilian, Cambodian, Chilean, Chinese, Croatian, Cuban, Cypriot, Czech, Danish, Dutch, Egyptian, El Salvadorian, Estonian, French, German, Ghanan, Gibraltar, Greek, Haiti, Hong Kong, Hungarian, Indian, Iran, Irish, Israel, Italian, Kazakh, Lithuanian, Luxembourgian, Malaysian, Malta, Mexican, Monaco, Morocco, New Zealand, Nigerian, Norwegian, Peruvian, Polish, Romanian, Russian, Rwandan, Seychelles, Singapore, Slovakian, South African, South Korean, South Osetian, Spanish, Sri Lankan, Sudan, Swedish, Swiss, Thailand, Tunisian, Turkish, Liechtenstein, UK, US, Venezuelan, and Vietnamese numbers.
And to some extent, all others. Just try if it works for you.
@@ -680,9 +680,22 @@
country '968', todo # Oman (Sultanate of)
country '969', todo # Reserved - reservation currently under investigation
- country '970', todo # Reserved
+ country '970', # 970 is used in those countries that block access to 972 (Israel)
+ one_of('1') >> split(3,3,3) | # special numbers
+ one_of('2', '3', '4', '8', '9') >> split(3,4) | # 1 digit ndc
+ match(/^(5[023456789]|7[23467])\d+$/) >> split(3,4), # 2 digit ndc
+ length( 1 => 8, 2 => 9 ) # doesn't validate service numbers
+
country '971', todo # United Arab Emirates
- country '972', todo # Israel (State of)
+
+ # Israel (State of) (also works for numbers in Palestinian territories)
+ country '972',
+ one_of('1') >> split(3,3,3) | # special numbers
+ one_of('2', '3', '4', '8', '9') >> split(3,4) | # 1 digit ndc
+ match(/^(5[023456789]|7[23467])\d+$/) >> split(3,4), # 2 digit ndc
+ length( 1 => 8, 2 => 9 ) # doesn't validate service numbers
+
+
country '973', todo # Bahrain (Kingdom of)
country '974', todo # Qatar (State of)
country '975', todo # Bhutan (Kingdom of)
@@ -187,6 +187,26 @@ def self.it_splits number, expected
it_splits '353800123456', ['353', '800', '123456'] # Freefone
it_splits '353000123456', ['353', '000', '123456'] # Default fixed 3 split for unrecognized
end
+
+ describe 'Israel (972)' do
+ it_splits '972100', ['972', '1', '00'] # Police
+ it_splits '97221231234', ['972', '2', '123', '1234'] # Jerusalem Area
+ it_splits '97282411234', ['972', '8', '241', '1234'] # Gaza Strip (Palestine)
+ it_splits '97291231234', ['972', '9', '123', '1234'] # Sharon Area
+ it_splits '972501231234', ['972', '50', '123', '1234'] # Mobile (Pelephone)
+ it_splits '972591231234', ['972', '59', '123', '1234'] # Mobile Jawwal (Palestine)
+ it_splits '972771231234', ['972', '77', '123', '1234'] # Cable Phone Services
+ it_splits '9721700123123', ['972', '1', '700', '123', '123'] # Cable Phone Services
+ end
+ describe 'Israel (970)' do
+ it_splits '97021231234', ['970', '2', '123', '1234'] # Jerusalem Area
+ it_splits '97082411234', ['970', '8', '241', '1234'] # Gaza Strip (Palestine)
+ it_splits '97091231234', ['970', '9', '123', '1234'] # Sharon Area
+ it_splits '970501231234', ['970', '50', '123', '1234'] # Mobile (Pelephone)
+ it_splits '970591231234', ['970', '59', '123', '1234'] # Mobile Jawwal (Palestine)
+ it_splits '970771231234', ['970', '77', '123', '1234'] # Cable Phone Services
+ it_splits '9701700123123', ['970', '1', '700', '123', '123'] # Cable Phone Services
+ end
describe 'Italy' do
it_splits '3934869528', ['39', '348', '695', '28'] # Mobile
it_splits '393357210488', ['39', '335', '721', '0488'] # Mobile
@@ -126,7 +126,11 @@
Phony.plausible?('+49 31234 123456').should be_true
Phony.plausible?('+49 31234 1234567').should be_false
end
-
+
+ it 'is correct for Isralian numbers' do
+ Phony.plausible?('+972 2 123 1234').should be_true
+ Phony.plausible?('+972 59 123 1234').should be_true
+ end
it "is correct for US numbers" do
# Sorry, still need E164 conform numbers.
#

0 comments on commit f40cd6b

Please sign in to comment.