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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

aclight’s picture

Project: Google Highly Open Participation Contest (GHOP) » Phone
Version: » master
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/...

ezyang’s picture

Assigned: Unassigned » ezyang
Status: Active » Needs review
FileSize
16.51 KB

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! :-)

ezyang’s picture

FileSize
16.59 KB

Updated patch that fixes some formatting style problems.

bdragon’s picture

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.

ezyang’s picture

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.

bdragon’s picture

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

ezyang’s picture

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

ezyang’s picture

FileSize
19.32 KB

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

ezyang’s picture

FileSize
20.37 KB

Update patch with extra documentation.

ezyang’s picture

FileSize
20.82 KB

Updated patch... with even more documentation!

aclight’s picture

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.

waddles’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +GHOP

@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.

KrisBulman’s picture

whats the status of this?

asak’s picture

subscribing.

tsvenson’s picture

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?

greenbeans’s picture

Also curious about status.

gnindl’s picture

Title: GHOP #165: International phone numbers for CCK » International phone numbers for CCK (ITU)
Version: master » 6.x-2.8
Assigned: ezyang » gnindl
Status: Needs work » Needs review
FileSize
18.34 KB

Ported the patch to Drupal 6.

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

tryitonce’s picture

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 -

gnindl’s picture

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.

tryitonce’s picture

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

greg.harvey’s picture

Version: 6.x-2.8 » 6.x-2.16

I'm confused - I'm using the latest 6.x approved version and I cannot enter French numbers using the International Phone Numbers widget - they fail validation every time with this:

"+33 XXXXXXXXX" is not a valid international phone number

Weird! Does this not work in the 2.x branch? It seems it was maybe never committed, though the UI offers the option.

alvinet’s picture

I'm confused too... I can't validate Italian, Swiss and many more phone numbers.
I don't know if this is a dumb question but... what is the situation about phone number prefix checks?
Does it support only +1 and +44 prefix? (for me seems that only this works)

inforeto’s picture

Version: 6.x-2.16 » 6.x-2.17

Version 6.x-2.17 now has an array of country codes to load the appropiate inc file.
Numbers without a country code should default to 1 and load phone.ca.inc which might not validate some numbers.
In my testing, it refused to validate a mx number 6621884677 because of the 1 on the fourth digit, phones with 2 or 8 pass validation.

jessia’s picture

I just can't for the life of me get this to work. Every number I entered came back as "this is not a valid international phone number". I was trying my Thai number (+66 XXXXXXXXXX) and couldn't get it to work, so I thought maybe Thailand wasn't supported. Tried my US phone number (+1 XXXXXXXXXX), again no luck. Tried with and without spaces, with and without the +. Nothing. As far as I can tell, the international phone number option is completely useless... Has anyone else been able to make it work?

tamerzg’s picture

Category: task » bug
Priority: Normal » Major

It seems that problem is in phone.int.inc file in line 48-53.
There it tries to validate international numbers based on country validation inc file, but for most countries there is no file so it will always return false.

Changing the code a little bit should make it work:

$countrycode = phone_country_code_convert($cc);
$valid_phone_function = 'valid_'. $countrycode . '_phone_number';
module_load_include('inc', 'phone', 'phone.'. $countrycode);
if (function_exists($valid_phone_function)) {
return $valid_phone_function($phonenumber, $field);
}
else{
return TRUE;
}

thierry_gd’s picture

#25 taken into account in 6.2.18 release

loophole080’s picture

confirmed works for UK numbers with 6.2.18 (didn't in 6.2.17 for me) in formats:

+44 2081231234
+44(0)2081231234

it removes the (0) but accepts it being entered in the field anyway - doesn't like it without the (0)/space when entered