Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Argentina phone number formatting is quite broken #31

Closed
vilcsak opened this Issue · 13 comments

2 participants

@vilcsak

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

@floere
Owner

Thanks! It is horribly broken indeed, with a big fat TODO on top.

I'll think about a quick solution and pasting it here (for reference). Cheers!

@floere
Owner

Thanks for the test cases and the detailed writeup as well!

@vilcsak

Is there another country that has a similar setup with the area codes? If there's an existing case, I can probably figure things out.

@floere
Owner

Lithuania might be helpful, but I have to admit that I am wondering how to do the mobile numbers. Argentina is pretty unique in that they prepend a "mobile digit" in front of the normal numbering scheme.

@floere
Owner

This solves the case for fixed line numbers:

  country '54', one_of('11') >> split(4,4) |
                one_of("220",
                       "221",
                       "223",
                       "237",
                       "261",
                       "264",
                       "291",
                       "297",
                       "299",
                       "341",
                       "342",
                       "343",
                       "345",
                       "351",
                       "353",
                       "358",
                       "381",
                       "385",
                       "387",
                       "388") >> split(3,4) |
                fixed(4)      >> split(2,4)
@floere
Owner

@vilcsak Can you live with mobile number rendered as "+54 911 1234 5678"? (no space between 9 and 11) I need to do a little rewrite of Phony if this case needs to be covered.

@floere
Owner

(Please disregard my earlier attempt at a regexp – I was in the wrong mindset)

@floere
Owner

Got it, will release in 1.5.2 in 10 minutes.

  # Argentine Republic.
  #
  country '54', one_of('11', '911') >> split(4,4) | # Fixed & Mobile
                match(/^(22[0137]|237|26[14]|29[179]|34[1235]|35[138]|38[1578])/) >> split(3,4) |        # Fixed
                match(/^(922[0137]|9237|926[14]|929[179]|934[1235]|935[138]|938[1578])/) >> split(3,4) | # Mobile
                match(/^(9\d{4})/) >> split(2, 4) | # Mobile
                fixed(4) >> split(2,4) # Fixed
@vilcsak

Cool, this will certainly do for now. Would be great to have the true 9 support in the future.

@floere
Owner

Great! 1.5.2 is released, fixed with your input. Many thanks!

@floere floere closed this
@vilcsak

Upgraded, thanks!

@floere
Owner

@vilcsak Great! Please note that 1.6.0 has been released as well, lowering the possibility of cut-off numbers. Also find yourself in the special mentions section https://github.com/floere/phony/wiki/Contributors :)

@floere
Owner

Btw, I love the title "quite broken" … it's like the brits say "quite dead" :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.