International phone numbers for CCK (ITU)

Thomas_Zahreddin - January 20, 2008 - 21:35
Project:Phone (CCK)
Version:6.x-2.8
Component:Code
Category:task
Priority:normal
Assigned:gnindl
Status:needs review
Issue tags:GHOP
Description

Task description / Requirements:
Create an abstraction of the existing filters for phone numbers, so that the filter (to be created) works for all country-codes, therefor:
+ add a configuration option for a default country code,
+ The new filter should validate the number from the user-input against the rules of ITU: validate the country code if started with a "+" sign
+ add a default country-code if the user didn't typed it in, delete therefor a leading 0
+ add a configuration option for the maximum number of digits a phone number is allowed to have (default 20; ITU recommondation 15 + Country-code)
+ test the length of the phone numbers (digits only) against the configured length, while ignoring all brackets, dots, dashes etc. form the user - input,

Approach:
Install drupal, cck and phone
create a input-type with a phone nuber, test the limits of the existing phone-module (not all country-codes can be used)
take the php-Editor / IDE of your choice
Learn how the existing filters are build (fr, us, ca, it, ru)
Create the configuration for the filter
Create the generic filter for all phone-numbers
Integrate the configuration: the filter and the existing phone-module

Versions:
phone is now only for D5 aviable, so the students / you will have to use D5 with the actual developer release of the phone module

Deliverable(s)
a new filter for phone (Ready for review)
a patch of phone.module to integrate the new filter (Ready for review)
at least one page of user documentation: Who defines country-codes? Where are they officiealy documented? What is the recommendation for the length of phone numbers? What signs are used to format a phone-number ?
The used standards should be described in the readme.txt, the appropriate places in the source-code and appropriate links should also placed on the configuration page.

Resources
http://ftp.drupal.org/files/projects/drupal-5.6.tar.gz
http://drupal.org/project/cck
IRC: #drupal
The phone modul: http://drupal.org/project/phone
http://en.wikipedia.org/wiki/List_of_country_calling_codes
RegEx - Tester: http://sourceforge.net/projects/kodos/
official list of country codes: http://www.itu.int/publ/T-SP-E.164D-2007/en
Number-format and -length:
http://www.antelope.org.uk/numbering/World_numbering_developments.pdf see section 2.1.1
a link to the general resources: http://code.google.com/p/google-highly-open-participation-drupal/wiki/Fu...

Maintainer for the module phone: Thierry Guégan; http://drupal.org/user/43798
(this task is on the to-do list of the module)

Primary contact
Thomas_Zahreddin http://drupal.org/user/118299
mailto:ghop@it-arts.org

#1

aclight - January 20, 2008 - 22:08
Project:Google Highly Open Participation Contest (GHOP)» Phone (CCK)
Version:<none>» HEAD
Component:GHOP Task» Code

Moving this to the phone.module issue queue.

The official task associated with this issue can be found at:
http://code.google.com/p/google-highly-open-participation-drupal/issues/...

#2

ezyang - January 21, 2008 - 23:09
Assigned to:Anonymous» ezyang
Status:active» needs review

Here's the full implementation of the task.

A few notes about some of the stipulations in the task that might raise some questions:

validate the country code if started with a "+" sign

Our validation of country code is restricted to checking if it is three digits or less. While a list of valid country codes could have been added to the patch with very little effort, I believe this is a bad idea: country codes can be quite volatile and it makes little sense to date the module.

delete therefor a leading 0

The convention of 0 as a trunk code is not uniform throughout all countries; where 7 or 8 has been explicitly set as a single digit, it has been removed too.

add a configuration option for the maximum number of digits a phone
number is allowed to have (default 20; ITU recommondation 15 + Country-code)

The stipulation here is plain wrong. The ITU says that international phone numbers SHALL NOT exceed 15 digits, so it's considerably lower than 20. I believe that this should not be configurable, either, due to the fact that length of numbers are inextricably linked to digit analysis by routers. I have set 15 and will stick by this decision.

test the length of the phone numbers (digits only) against the configured length, while ignoring all brackets, dots, dashes etc. form the user - input,

Validation is considerably more lenient than comparable modules. For example, +1 [732] (234) (333) is considered a valid phone number, which normalizes to +1 732 234 333. Because of the re-formatting capabilities of the Phone module, I believe this is reasonable behavior.

Please review! There are also some miscellaneous refactorings/coding style changes. I recommend that all files in Phone be run through coder_format. Oh, and did I mention, there are unit tests! :-)

AttachmentSize
phone-1.patch 16.51 KB

#3

ezyang - January 21, 2008 - 23:35

Updated patch that fixes some formatting style problems.

AttachmentSize
phone-2.patch 16.59 KB

#4

bdragon - January 21, 2008 - 23:50

Visually inspected patch. Excellent patch.

Other than noting the TODO regarding matching brackets, and a couple of patch bands with slightly suspect indentation (see code block), I cannot find any problems visually.

-  || $countrycode == 'ru') {
+  || $countrycode == 'ru'
+    || $countrycode == 'int') {

I don't have a test site handy for this, so someone else needs to check that it runs as intended, but I say it's good to go with a quick functional review by someone.

#5

ezyang - January 21, 2008 - 23:57

BDragon: The suspect indentation already existed in the module. I can post another patch with all the formatting normalized, but that would make it difficult to visually inspect the patch and see what functional changes were made.

#6

bdragon - January 22, 2008 - 00:17

I was only referring to the two extra spaces before the || on the second + line. The rest looks good.

#7

ezyang - January 22, 2008 - 00:18

Yeah. That's because there's tabs (crowd gasps) in the source file.

#8

ezyang - January 22, 2008 - 03:52

Updated patch, with friendly error reporting, and checking for foreign characters.

AttachmentSize
phone-3.patch 19.32 KB

#9

ezyang - January 22, 2008 - 04:27

Update patch with extra documentation.

AttachmentSize
phone-4.patch 20.37 KB

#10

ezyang - January 22, 2008 - 04:44

Updated patch... with even more documentation!

AttachmentSize
phone-5.patch 20.82 KB

#11

aclight - January 22, 2008 - 04:52
Status:needs review» reviewed & tested by the community

I gave this a pretty thorough testing and couldn't find any problems with it. It seems like the standard itself is a bit vague and at times nonspecific, but I think ezyang did his best given the standard. He even threw in some simple tests to make testing future changes to the code more reliable. This is great work.

#12

wad - April 15, 2008 - 04:55
Status:reviewed & tested by the community» needs work

@ezyang #2 - The limit of 15 digits is a strong recommendation, not a mandate. The Australian National Numbering Plan is at least one NNP where the ITU-T recommendation is ignored, allowing a maximum numbering length (excluding the country code) of 15 digits.

#13

KrisBulman - February 26, 2009 - 00:25

whats the status of this?

#14

asak - March 7, 2009 - 13:16

subscribing.

#15

edde42 - April 10, 2009 - 14:26

I am working on a multisite that will share content between sites and where for example phone numbers will be different depending on which site a node is viewed on. It will also have the Internationalization module for content translation.

Will I be able to show different phone numbers, correctly formatted, depending on which of the sites the visitor reads the page on?

Will I also be able to have different phone numbers depending on the language version of the node?

#16

greenbeans - April 13, 2009 - 22:35

Also curious about status.

#17

gnindl - June 24, 2009 - 16:26
Title:GHOP #165: International phone numbers for CCK» International phone numbers for CCK (ITU)
Version:HEAD» 6.x-2.8
Assigned to:ezyang» gnindl
Status:needs work» needs review

Ported the patch to Drupal 6.

Default maximum number length is 15, but can be set to any number in the widget settings.

AttachmentSize
phone_ITU_patch_6.x.txt 18.34 KB

#18

tryitonce - June 28, 2009 - 13:31

Thanks for the job of porting.

I can't get the thing to work though and have a few questions:

  1. Would it not be easier to include the whole phone.module code patched - it seems there is a lot of code and it is not easy to see what needs to be patched exactly as a lot of lines have a "-" to be relpaced "+" with the exact same line? Or is this against the etiquette of respecting each others work - so I will not put my foot into it once I might try and help patching. Thanks ;-).
  2. I managed to patch phone.module with ironing out a couple of hitches.
  3. I also created the file phone.int.inc as all fields and error messages show up.
  4. With all the options I tried - see below - I am getting the error messages when I enter the phone number -
    "34 950343434" is not a valid international phone number.
    International phone numbers should contain a country code prefixed by a plus sign followed by the local number.
    I get this same message if I enter the phone number as "+34" - "+34 950343434" is not ....
  5. I have been trying all the input options - as far as I can see. So here are the problems I find:
    • Maximum length of international numbers, according to the ITU this is 15: - is there a value required or can it remain blank - I left it blank and I added 15. - Same error message as above.
    • As input format in the user profile I tried "34 950343434" and "+34 950343434" - the error message just shows me the number exactly as entered with or without the "+".
    • Actually, the instruction "Default country code to add to international numbers without one (omit + sign): is not quite clear - What is meant with "....without one (omit + sign)"? I believe this means 1 for USA is not to be included and all the country codes should be entered with out the plus "+" - i.e. 34 for Spain as the default.
  6. I ran cron and flash all memory in between all those changes.

I would be greatful for all and any help. I guess it's just one of these little oversights on my side.

by the way on line 123 of the patch there is the line .... This field type is based off of the ... - I guess this should be: .... This field type is based on the ......

Thank you -

#19

gnindl - June 30, 2009 - 10:18

tryitonce have a look at the following thread:

http://drupal.org/node/501060

I reengineered and submitted the whole module and made it more plug & play for adding new phone validations.

I skipped the "Default country code" options there.

Unfortunately it's not approved yet.

#20

tryitonce - June 30, 2009 - 23:00

Thanks - I am testing and more on http://drupal.org/node/501060

 
 

Drupal is a registered trademark of Dries Buytaert.