floere / phony Goto Github PK
View Code? Open in Web Editor NEWE164 international phone number normalizing, splitting, formatting.
Home Page: http://florianhanke.com/phony/
License: MIT License
E164 international phone number normalizing, splitting, formatting.
Home Page: http://florianhanke.com/phony/
License: MIT License
Given a number from an "unsupported" country like Bangladesh, Phony will drop digits when calling format.
Phony.normalize("+8801552405452")
=> "8801552405452"
Phony.format("8801552405452") # the normalized number
=> "+880 15 524 05 45" # Note the missing 2
We have a Machinist blueprint that reads:
Address.blueprint do
address_1 { Faker::Address.street_address }
...
country { %w{ DE FR IT AT }.rand }
state { "new" }
end
The line with "country" clashes with Phony's own country DSL. Not sure who is to blame though :)
The following:
phone = "123-123-1234"
Phony.plausible?(phone)
puts phone
will print "1231231234"
Phony appears to be normalizing strings when plausible? is called. This is not expected (plausible should be side effect free).
Add a
require 'phony_without_countries'
so that users can load the countries separately, like so:
require 'phony/countries/south_korea'
require 'phony/countries/sweden'
.
it "should normalize a number with erroneous zero inside" do
Phony.normalize('+410443643533').should == '41443643533'
end
This will cause a valid US phone number, such as "310-897-8881" to be normalized to "318908881".
Is this example as intended?
it "should normalize a number with colons" do
Phony.normalize('1.906.387.1698').should == '19063871698'
end
https://github.com/floere/phony/blob/master/spec/lib/phony_spec.rb#L48-L50
Phony.normalize('1')
'1'
"1[#<Phony::NationalCode:0x982504c @national_splitter=#<Phony::NationalSplitters::Fixed:0x9825254 @SiZe=3, @zero=nil>, @local_splitter=#<Phony::LocalSplitters::Fixed:0xa7e6be8 @Format=[3, 14]>, @normalize=true>]"
Note, I'm using version 1.7.2.
Thanks for a great gem,
Declan
I'm trying to build a select menu for the user to choose their country, and auto-populate the country code.
Couldn't see an easy way to get a hash or array of these values though to build the select. Any ideas? Thanks for the great gem btw.
Phony.normalize('3')
NoMethodError: undefined method `normalize' for 1:Fixnum
Phony.normalize('ewrg')
NoMethodError: undefined method `normalize' for 1:Fixnum
Phony.normalize('1ewrg')
=> "1[#<Phony::NationalCode:0x007fbb06bfdab0 @national_splitter=#<Phony::NationalSplitters::Fixed:0x007fbb06bfdb00 @size=3, @zero=nil>, @local_splitter=#<Phony::LocalSplitters::Fixed:0x007fbb06cde470 @format=[3, 14]>, @normalize=true>]"
Perhaps it should throw its own error class, or simply return the input back again
In Brazil we currently have several carrier codes, like described in Wikipedia: http://en.wikipedia.org/wiki/Brazilian_Carrier_Selection_Code
Could phony support this?
Thank you!
NDC's with 5 digits are not recognized. Example:
it "should handle Geithain" do
Phony.split('493434144602').should == ['49', '34341', '446', '02']
end
Wrong result: ['49', '3434', '144', '602']
Hm, found this comment in https://github.com/floere/phony/blob/master/lib/phony/countries/germany.rb:
# Note: Germany uses a variable ndc format from length 2 to 5.
# To save space, we only use ndcs up to length 4.
Maybe you wannt to use the data from a similar (but more simple) gem created by me:
https://github.com/ledermann/dialy/blob/master/lib/dialy/data/de.rb
In my gem I have included all NDC's (not only 2 to 4), so a validation check is possible, too.
In some countries phone numbers are prefixed with a 0 and provide no country code. I'd like a way, given a ISO-3166 2-letter country code as a hint, to have the numeric E164 country code prepended and the 0 removed.
Is there any way to do this right now with phony? If not, any thoughts on how to go about doing it?
Thanks!
Sincerely,
Anthony Eden
Just a project organization issue. Technically it's not good to put a file directly under lib that doesn't share the name of your project. So specifically in Phony's case, the countries.rb
file should be moved to the phony/
directory. The reason being, if someone else wanted to create a project called countries
then there would be a naming conflict.
German service numbers, with the 180 or 181 prefix are incorrectly split:
+49 180 587 8323 should have have 180 as the second block, but splits like this:
["49", "1805", "878", "323"]
Hi,
There certainly must be a reason but why is a string with characters considered as valid ?
ex : +33123456789-blabla
Thanks
# Phony 1.8.4
> Phony.normalize('3109999999')
=> "319999999"
> Phony.normalize('13109999999')
=> "13109999999"
Not sure why the number is being dropped in the former case. The plausible?
method returns true for both (whether or not country code is specified), but there's no way to specify country code to normalize in an attempt to fix this.
Thoughts? Thanks!
Expression ['1', *('3200'..'3209').to_a, 1]
is not compatible with Ruby 1.8 (invalid syntax, due to 1.8 parsing restrictions). (see /lib/phony/countries/italy.rb)
Cheers,
Gleb
Phony.normalize("650 561 5158")
=> "655615158"
Phony.split("4578775130")
=> ["45", false, "78", "77", "51", "30"]
Not sure if the false value in the return value from split is correct? Should that be a 0? or Is it an error to have a boolean instead of a string?
Thanks!
Why not just Phony.format()
instead of Phone.formatted()
?
BTW, love the "Brrringggg! " at the bottom of the webpage :-)
It looks like Belgian mobile numbers are formatting incorrectly:
+32 497 54 67 47 is formatted as +32 4 975 4674, which according to wikipedia is incorrect: http://en.wikipedia.org/wiki/Telephone_numbers_in_Belgium
It is a real number, as well
Thanks!
Keith
A number like "390612345678" will not format correctly. The last digit will be dropped and the formatted number will end up looking like this: "+39 06 123 4567"
The problem is in the last handler defined in phony/countries/italy.rb. The local splitter there will split the number into three digits and then four, dropping off the last digit. This works just fine for 3 or more digit NDCs obviously. :)
This example shows an Irish phone number...
Phony.plausible?('353345435') # => true
Phony.format('353345435', :format => :national)
NoMethodError Exception: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.empty?
You can get the national version of the number from the international number using ...
Phony.format('353345435').split(' ')[1..-1]
This is what I wanted to do in my model:
def phone_number=(phone_number)
write_attribute(:phone_number, Phony.normalize(phone_number))
end
def phone_number
Phony.format(read_attribute(:phone_number))
end
(I know, a representer/decorator would not be bad.)
This is my spec for this feature:
require 'spec_helper'
describe Phone do
describe "phone number normalization and formation" do
let(:person) {Fabricate.build(:person)}
it "using %phone_number=" do
person.phones = []
person.phones << Phone.new
person.phones.first.phone_number = "+491618674135"
person.phones.first.phone_number.should eq("+49 161 867 4135")
person.phones.first[:phone_number].should eq("491618674135")
end
it "using %attributes" do
hash = {"phones_attributes"=>[{
"_id"=>person.phones.first.id,
"phone_number"=>"+491618674135"
}]}
person.attributes = hash
person.should be_valid
person.phones.first.phone_number.should eq("+49 161 867 4135")
person.phones.first[:phone_number].should eq("491618674135")
end
it "using %[]=" do
person.phones.first[:phone_number] = "+491618674135"
person.should be_valid
person.phones.first.phone_number.should eq("+49 161 867 4135")
end
it "does not fail if phone_number is nil" do
person.phones.first.phone_number = nil
person.should be_valid
person.phones.first.phone_number.should be_nil
person.phones.first.phone_number = "+491618674135"
person.phones.first[:phone_number] = nil
person.should be_valid
person.phones.first.phone_number.should be_nil
end
end
end
when I run this spec, I get the following error messages:
Phone
phone number normalization and formation
using %phone_number=
using %attributes
using %[]= (FAILED - 1)
does not fail if phone_number is nil (FAILED - 2)
Failures:
1) Phone phone number normalization and formation using %[]=
Failure/Error: person.should be_valid
NoMethodError:
undefined method `split' for 1:Fixnum
# ./app/models/phone.rb:45:in `phone_number'
# ./spec/models/phone_spec.rb:33:in `block (3 levels) in <top (required)>'
2) Phone phone number normalization and formation does not fail if phone_number is nil
Failure/Error: person.phones.first.phone_number = nil
TypeError:
can't dup NilClass
# ./app/models/phone.rb:41:in `phone_number='
# ./spec/models/phone_spec.rb:38:in `block (3 levels) in <top (required)>'
Finished in 0.23927 seconds
4 examples, 2 failures
Failed examples:
rspec ./spec/models/phone_spec.rb:31 # Phone phone number normalization and formation using %[]=
rspec ./spec/models/phone_spec.rb:37 # Phone phone number normalization and formation does not fail if phone_number is nil
In the end, I came up with the following to get this spec running.
def phone_number=(phone_number)
value = Phony.normalize(phone_number) unless phone_number.nil?
write_attribute(:phone_number, value)
end
def phone_number
@phone_number_loop ||= 0
Phony.format(read_attribute(:phone_number)) unless read_attribute(:phone_number).nil?
rescue NoMethodError => error
@phone_number_loop += 1
self.phone_number = self[:phone_number]
if @phone_number_loop == 1
phone_number
else
raise error
end
end
It would be nice, if
Phony.normalize
could handle nilPhony.format
could also handle nilPhony.format
would run a string through Phony.normalize when the string was not normalized before, instead of failing.Phony
would convert anything it gets to String before processing it to avoid failing when it is not necessary.Thanks!
Tobias
I'd implement this fix myself, but don't truly understand enough about how the gem works to make the changes.
Right now, we format all Argentina numbers as +54 xx xxx xxx. They should be formatted as:
A) Local numbers. Many area codes, 2-4 digits. Different area codes result in the remainder of the number being formatted differently.
+54 11 1234 5678
+54 291 123 4567
+54 2965 12 3456
B) Mobile numbers. Follows above convention, but "9" is prepended to all numbers.
+54 9 11 1234 5678
+54 9 220 123 3457
+54 9 2221 12 3455
Full of list of area codes, as scraped from http://www.cnc.gov.ar/infotecnica/numeracion/indicativosinter.asp?offset=0 (using http://sak.to/0612291C3x1U1S0B1g0G):
11, 220, 2202, 221, 2221, 2223, 2224, 2225, 2226, 2227, 2229, 223, 2241, 2242, 2243, 2244, 2245, 2246, 2252, 2254, 2255, 2257, 2261, 2262, 2264, 2265, 2266, 2271, 2272, 2273, 2274, 2281, 2283, 2284, 2285, 2286, 2291, 2292, 2293, 2314, 2316, 2317, 2320, 2322, 2323, 2324, 2325, 2326, 2337, 2342, 2343, 2344, 2345, 2346, 2352, 2353, 2354, 2355, 2356, 2357, 2358, 2268, 2296, 2297, 2362, 2267, 237, 2392, 2393, 2394, 2395, 2396, 2473, 2474, 2475, 2477, 2478, 291, 2921, 2922, 2923, 2924, 2925, 2926, 2927, 2928, 2929, 2932, 2933, 2935, 2936, 2982, 2983, 3327, 3329, 3382, 3388, 3407, 3461, 3487, 3488, 3489, 3832, 3833, 3835, 3837, 3838, 3711, 3715, 3721, 3722, 3725, 3731, 3732, 3734, 3735, 3877, 297, 2965, 2945, 2903, 3385, 3387, 2336, 3472, 3463, 3467, 3468, 351, 3521, 3522, 3524, 3525, 353, 3532, 3533, 3534, 3541, 3542, 3543, 3544, 3546, 3547, 3548, 3549, 3562, 3563, 3564, 3571, 3572, 3573, 3574, 3575, 3576, 358, 3582, 3583, 3585, 3584, 3756, 3772, 3773, 3774, 3775, 3777, 3781, 3782, 3783, 3786, 345, 3454, 3455, 3456, 3458, 343, 3435, 3436, 3437, 3438, 3442, 3444, 3445, 3446, 3447, 3716, 3718, 3717, 388, 3884, 3885, 3886, 3887, 2941, 2338, 2333, 2334, 2335, 2331, 2302, 2952, 2953, 2954, 3821, 3822, 3825, 3826, 3827, 261, 2622, 2623, 2624, 2625, 2626, 2627, 3741, 3743, 3758, 3757, 3755, 3754, 3751, 3752, 2942, 2948, 299, 2972, 2944, 2946, 2940, 2934, 2931, 2920, 3878, 3876, 3868, 387, 3875, 264, 2646, 2647, 2648, 2651, 2652, 2658, 2655, 2656, 2657, 2902, 2962, 2963, 2966, 342, 3408, 3406, 3409, 341, 3400, 3401, 3402, 3404, 3405, 3462, 3460, 3469, 3471, 3464, 3465, 3466, 3476, 3482, 3483, 3491, 3492, 3493, 3498, 3496, 3497, 3857, 3858, 3861, 3844, 3845, 3846, 385, 3854, 3855, 3856, 3841, 3843, 2964, 2901, 381, 3862, 3863, 3865, 3867, 3869, 3894, 3891, 3892
Phony.normalize('+41 44 364 35 33').should == '41443643533'
works correctly. It would be nice, if Phony also supported the "Double Zero" syntax:
Phony.normalize('0041 44 364 35 33').should == '41443643533'
It would be great if there could be more support for Israel number formats. Would be interested in sponsoring the development of this if interested please contact me directly todd dot fisher at gmail dot com
Hi,
I'm using the Fabrication gem (http://rubygems.org/gems/fabrication) in combination with the Faker gem (http://rubygems.org/gems/faker) to generate test data for a project I'm working on currently which looks something like this..
Fabricator(:phone_number) do
phone_number { Faker::PhoneNumber.phone_number }
end
Thru this I landed on the phone number "7209175276" which returns an error. I repeated the same process on the console and got the same error
1.9.3p194 :001 > include Phony
=> Object
1.9.3p194 :002 > Phony.formatted("7209175276")
NoMethodError: undefined method `size' for nil:NilClass
from /Users/imoss/.rvm/gems/ruby-1.9.3-p194@admissions/gems/phony-1.7.6/lib/phony/national_splitters/regex.rb:38:in `split'
from /Users/imoss/.rvm/gems/ruby-1.9.3-p194@admissions/gems/phony-1.7.6/lib/phony/national_code.rb:19:in `split'
from /Users/imoss/.rvm/gems/ruby-1.9.3-p194@admissions/gems/phony-1.7.6/lib/phony/country.rb:30:in `block in split'
from /Users/imoss/.rvm/gems/ruby-1.9.3-p194@admissions/gems/phony-1.7.6/lib/phony/country.rb:29:in `each'
from /Users/imoss/.rvm/gems/ruby-1.9.3-p194@admissions/gems/phony-1.7.6/lib/phony/country.rb:29:in `split'
from /Users/imoss/.rvm/gems/ruby-1.9.3-p194@admissions/gems/phony-1.7.6/lib/phony/country_codes.rb:44:in `split'
from /Users/imoss/.rvm/gems/ruby-1.9.3-p194@admissions/gems/phony-1.7.6/lib/phony/country_codes.rb:48:in `formatted'
from /Users/imoss/.rvm/gems/ruby-1.9.3-p194@admissions/gems/phony-1.7.6/lib/phony.rb:79:in `format!'
from /Users/imoss/.rvm/gems/ruby-1.9.3-p194@admissions/gems/phony-1.7.6/lib/phony.rb:76:in `format'
from (irb):2
from /Users/imoss/.rvm/gems/ruby-1.9.3-p194@admissions/gems/railties-3.2.3/lib/rails/commands/console.rb:47:in `start'
from /Users/imoss/.rvm/gems/ruby-1.9.3-p194@admissions/gems/railties-3.2.3/lib/rails/commands/console.rb:8:in `start'
from /Users/imoss/.rvm/gems/ruby-1.9.3-p194@admissions/gems/railties-3.2.3/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I'm not sure if this phone number is valid or not (some googling suggested that it is not) but I would suggest that it if it is not valid it should return some more useful error, or better yet just the string that was passed in.
Given a phone number and a country, is there a way to tell whether it's valid or not using phony
?
Phony.normalize('020')
=> "20[#<Phony::NationalCode:0x007f92abd88c28 @national_splitter=#<Phony::NationalSplitters::Variable:0x007f92abd88db8 @size=nil, @zero=\"0\", @mapped_ndc_min_length=3, @mapped_ndc_max_length=3, @ndcs={3=>[\"800\"]}>, @local_splitter=#<Phony::LocalSplitters::Fixed:0x007f92abd88c50 @format=[17]>, @normalize=true>, #<Phony::NationalCode:0x007f92abd889a8 @national_splitter=#<Phony::NationalSplitters::Variable:0x007f92abd88b10 @size=nil, @zero=\"0\", @mapped_ndc_min_length=1, @mapped_ndc_max_length=1, @ndcs={1=>[\"2\", \"3\"]}>, @local_splitter=#<Phony::LocalSplitters::Fixed:0x007f92ac2e7e58 @format=[18]>, @normalize=true>, #<Phony::NationalCode:0x007f92abd88890 @national_splitter=#<Phony::NationalSplitters::Fixed:0x007f92abcea960 @size=2, @zero=\"0\">, @local_splitter=#<Phony::LocalSplitters::Fixed:0x007f92ac2e7e58 @format=[18]>, @normalize=true>]"
Google seems to have done a great job of pulling all this information together here:
I'm having issues validating (plausiblating?? haha) number for countries such as Denmark
Phony.plausible?('45 44 11 22 33') # => false
It is weird (I would expect it to return true
) because I can see the country definition in the countries.rb file. And it also matches what wikipedia says
I tried the same thing with with others using the none
matcher like Liechtenstein and those don't work either.
Ideas?
Thanks!
Phony.normalize('0000000')
=> NoMethodError: undefined method `normalize' for 1:Fixnum
Phony.normalize('hello')
=> NoMethodError: undefined method `normalize' for 1:Fixnum
Formatting a real italian number (Rome area)
Phony.formatted('+39 0639 751474', :format => :international)
Raises the following exception:
NoMethodError: undefined method `split' for 1:Fixnum
from /home/gleb/phony/lib/phony/country_codes.rb:19:in `split'
Is it possible to identify unsupported countries, so that I could use Phony-based validations for those that are supported and fall back to some basic validations for those that are not?
I am using the latest version 1.9.0
I tried to display this number 20000001 (the 20 is for country code and the rest is the phone number)
Phony.plausible? returns true
Phony.normalize returns 201 and if i try to display it like this
Phony.formatted(Phony.normalize("20000001"), :format => :interrnational) this returns +20 1
while
Phony.formatted("20000001", :format => :interrnational) returns +20 00 0001
I would expect that Phony.normalize to return 000001 instead of just 1. But please let me know if i am wrong and what would be the expected behaviour in this case.
(rdb:1) e Phony.normalize "00000001"
"1[#<Phony::NationalCode:0x007fff332edfd0 @national_splitter=#<Phony::NationalSplitters::Fixed:0x007fff332ee020 @size=3>, @local_splitter=#<Phony::LocalSplitters::Fixed:0x007fff3335a298 @format=[3, 14]>, @normalize=true>]"
(rdb:1) e Phony.normalize "00000000"
NoMethodError Exception: undefined method `normalize' for 1:Fixnum
(rdb:1) e Phony.normalize "0"
NoMethodError Exception: undefined method `normalize' for 1:Fixnum
(rdb:1) e Phony.normalize "1"
"1[#<Phony::NationalCode:0x007fff332edfd0 @national_splitter=#<Phony::NationalSplitters::Fixed:0x007fff332ee020 @size=3>, @local_splitter=#<Phony::LocalSplitters::Fixed:0x007fff3335a298 @format=[3, 14]>, @normalize=true>]"
Sometimes (mostly), the input does not have a 1, but I want to add a 1 before proceessing it through our fax api. Is there a way to do that?
Hi, I get an error when using the "should" method saying it doesn't exist. When I remove, it seems to be working....
Phony.normalize('6509496092')
=> "659496092"
I don't think that's right........
1.9.3p125 :020 > Phony.plausible?("010")
=> true
1.9.3p125 :021 > Phony.normalize("010")
=> "1[#<Phony::NationalCode:0x007ffc2efc53a0 @national_splitter=#<Phony::NationalSplitters::Fixed:0x007ffc2efc53f0 @SiZe=3, @zero=nil>, @local_splitter=#<Phony::LocalSplitters::Fixed:0x007ffc2d5d3d70 @Format=[3, 14]>, @normalize=true>]"
1.9.3p125 :022 > Phony.plausible?("+460000")
=> true
1.9.3p125 :023 > Phony.normalize("+460000")
=> "46[#<Phony::NationalCode:0x007ffc2efe2f40 @national_splitter=#<Phony::NationalSplitters::Variable:0x007ffc2efe3120 @SiZe=nil, @zero="0", @mapped_ndc_min_length=2, @mapped_ndc_max_length=5, @ndcs={2=>["99"], 3=>["112", "116", "118", "900", "939", "944"], 4=>["1177"], 5=>["11414"]}>, @local_splitter=#<Phony::LocalSplitters::Fixed:0x007ffc2e97f338 @Format=[3, 13]>, @normalize=true>, #<Phony::NationalCode:0x007ffc2efe2cc0 @national_splitter=#<Phony::NationalSplitters::Variable:0x007ffc2efe2e50 @SiZe=3, @zero="0", @mapped_ndc_min_length=1, @mapped_ndc_max_length=2, @ndcs={1=>["7", "8"], 2=>["10", "11", "13", "16", "18", "19", "20", "21", "23", "26", "31", "33", "35", "36", "40", "42", "44", "46", "54", "60", "63", "90", "70", "71", "72", "73", "74", "76"]}>, @local_splitter=#<Phony::LocalSplitters::Fixed:0x007ffc2d3a6bb0 @Format=[18]>, @normalize=true>]"
There is no phone check for Estonia.
Estonian code is 372
mobile's regexp is ^(5|81|82), others are fixed. We have number portability this means, that we cannot separate numbers by region.
Finally, as we are located in European Union, then 112 and 110 are the numbers if something happens to you
Example:
Phony.split(Phony.normalize("+972"))
->
["972", "[#<Phony::NationalCode:0x007ffafe4d9fa8 @national_splitter=#<Phony::NationalSplitters::None:0x007ffafe4be190>, @local_splitter=#<Phony::NationalSplitters::Default:0x007ffafe4c30c8>, @normalize=true>]"]
expected:
["972",nil,nil,nil]
can not run in vietnam
Actual behaviour:
When the string starts with "+" (e.g. "+14152339111") Phony.formatted crashes hard, giving the backtrace below
Expected behaviour:
Phony.formatted('+14152339111', space: '') returns '+14152339111' without crashing
irb(main):001:0> Phony.formatted('+14152339110', space: '')
NoMethodError: undefined method `split' for 1:Fixnum
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/phony-1.9.0/lib/phony/country_codes.rb:44:in `split'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/phony-1.9.0/lib/phony/country_codes.rb:48:in `formatted'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/phony-1.9.0/lib/phony.rb:80:in `format!'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/phony-1.9.0/lib/phony.rb:77:in `format'
from (irb):1
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in `start'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in `start'
from C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Calls to Italy do not remove the initial zero on area codes (zero denotes a geographic landine area code), as is done in most countries, e.g. Switzerland:
Phony.normalize('+41 (044) 364 35 33').should == '41443643533'
(Removes the 0 in the 044 area code (Kanton Zürich)).
Phony.normalize would remove the zero even for Italy. Thus: Rework the normalizer to be country specific. Normalizing up to and including the country code, then deferring the rest of the number to the country handler.
Like that, Italy can normalize without removing the initial zero.
'7' => fixed(3,
:local_format => [3, 2, 2]
),
This is not quite true.
Despite what Wikipedia says, many Russian area codes have, in fact, 4 or more digits.
Here is a valid list of Area codes in Russia (last column)
http://www.mtt.ru/info/codes/index.wbp?country=%D0%EE%F1%F1%E8%FF&countryCode=&city=&cityCode=
If you pass normalize a value it can't process, the following exception gets raised:
Phony.normalize('!') # => <NoMethodError: undefined method `normalize' for 1:Fixnum>
It seems like Phony should raise a more useful exception here that downstream code can reasonably deal with:
def normalize_phone_number(num)
Phony.normalize(num)
rescue Phony::ParseError => ex
errors.add(:base, "#{num} is not a valid number")
end
Happy to write a patch if you agree with this approach.
If phony incorrectly detects a wrong prefix, then e.g. formats it using split(3,3)
, instead of e.g. split(4,4)
it will format it incorrectly.
However, much worse, it will lose 2 digits. This will usually only be detected at (phone) call time, with very bad results.
I suggest making the split method more forgiving. Hackish way: Adding X to the last number passed in, where X is an arbitrary number, e.g. 5.
I tried installing this and it said it needed activesupport >3.0?
Is there a way to work in my Rails 2.3.x installation, it's exactly what I need
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.