When I enter a phone number and I choose UK countrycode, I get the following:
# Notice: Undefined index: #item in gb_formatter_default() (line 81 of \sites\all\modules\cck_phone\includes\phone.gb.inc).
# Notice: Use of undefined constant _uk_phone_rules - assumed '_uk_phone_rules' in gb_formatter_default() (line 86 of \sites\all\modules\cck_phone\includes\phone.gb.inc).
# Warning: preg_match(): Unknown modifier 'p' in gb_formatter_default() (line 86 of \sites\all\modules\cck_phone\includes\phone.gb.inc).

It works ok with US and other numbers.

Comments

Roze-1’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev

Same thing here, Problem occurs as with UK

warning: preg_match() [function.preg-match]: Unknown modifier 'p' in /home/mysite/public_html/iceds/sites/all/modules/cck_phone/includes/phone.gb.inc on line 85.
warning: preg_match() [function.preg-match]: Unknown modifier 'p' in /home/mysite/public_html/iceds/sites/all/modules/cck_phone/includes/phone.gb.inc on line 85.

vsailo’s picture

Same problem. But works with other countries.

BenK’s picture

Subscribing

tebb’s picture

Subscribing

Roze-1’s picture

Any advancement with this issue ?

ckng’s picture

Status: Active » Fixed

Fixed in dev.

Roze-1’s picture

StatusFileSize
new27.1 KB

Problem persist, Please check the image that i have attached.

Roze-1’s picture

Status: Fixed » Active

Forgot to Re-open .. And problem persists in dev and 6.x-1.0 version

roball’s picture

Title: problem with UK phone number validation » UK phone numbers only display as "+44-"
Version: 6.x-1.x-dev » 6.x-1.0
Priority: Normal » Major

I can confirm that - with the 6.x-1.0 version - any number put in when "UK (+44)" is selected, will not be displayed, even if country level validation has been disabled. You will just see "+44-".

As a quick workaround, you can edit gb_formatter_default() in "includes/phone.gb.inc":
$phone = $cc['code'] . '-' . $item['number'];

or, even better, completely disable the inclusion of the "phone.gb.inc" file by renaming it (for example to "phone.gb.inc.X").

tebb’s picture

To clarify: As I understand it this was reported as a D7 issue, so I guess it's probably a D6 and D7 issue.

roball’s picture

Yes, the bug is in both the latest D7 and D6 releases.

yesct’s picture

subscribing

yesct’s picture

I added some dpm in phone.gb.inc

function gb_formatter_default($element) {
  $item = $element['#item'];
  dpm($item);

  // Display a global phone number with country code.
  $cc = cck_phone_countrycodes($item['country_codes']);

  $result = preg_match(_uk_phone_rules(), $item['number'], $matches);
  dpm($result);
  dpm($matches);

  if ($result) {
    // output as +44 AA BBBB CCCC, +44 AAA BBB CCCC or +44 AAAA BBB CCC
    $phone =  $cc['code'] . $matches[1] .'-'. $matches[2] .' '. $matches[3];
    dpm($phone);
  }

  return $phone;
}

and the dpm($matches) returns an array with

    0 (String, 10 characters ) 1913334444
    1 (String, 0 characters )
    2 (String, 0 characters )
    3 (String, 0 characters )
    4 (String, 0 characters )
    5 (String, 0 characters )
    6 (String, 0 characters )
    7 (String, 0 characters )
    8 (String, 0 characters )
    9 (String, 0 characters )
    10 (String, 3 characters ) 191
    11 (String, 3 characters ) 333
    12 (String, 4 characters ) 4444
roball’s picture

Yea, the _uk_phone_rules() regex is the erroneous source.

yesct’s picture

Version: 6.x-1.0 » 6.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new3.03 KB

uk inc seems to be different from the other inc files in that is specifies the possible patterns as (using a bunch of ORs instead of just one pattern):

 $regex = '/^
      ([0]*)(2[03489])(\d{4})(\d{4})  # 02x [eight-digit local number]
      |
      ([0]*)(11[3-8])(\d{3})(\d{4})   # 011x [seven-digit local number]
      |
      ([0]*)(1[2-9]1)(\d{3})(\d{4})   # 01x1 [seven-digit local number]
      |
      ([0]*)(1[2-9][0|2-9]\d)(\d{5,6})   # 01xxx [mostly six-digit local numbers] (but not 01x1 codes)
    $/x';

http://php.net/manual/en/function.preg-match.php

says "If matches is provided, then it is filled with the results of search. $matches[0] will contain the text that matched the full pattern, $matches[1] will have the text that matched the first captured parenthesized subpattern, and so on. "

And since there are a bunch of parenthesized subpatterns, it returns an array of up to 13 or so elements. The other inc files and this one are trying to set the phone using matches[1] matches[2] and matches[3].

So, I re-wrote it, using an array of possible regular expressions and eliminating the parens around the [0] (which is not desired in the result);

I'm not sure what to return when no match is found.. it actually shouldn't get to that point (if it is validated using gb_validate_number() ). But leaving it to return the $phone like it is, is doing exactly what it was before. So, I'm leaving it that way.

I also took out the dash in the formatted number, and added a space between the country code and the phone number. I looked at a few uk numbers on the web and most seemed to just go with spaces.

$phone =  $cc['code'] . ' ' . $matches[1] . ' ' . $matches[2] . ' ' . $matches[3];

Needs testing for cases that will match each of the possible patterns.

yesct’s picture

StatusFileSize
new3.07 KB

I took off trailing white space and made my comment a sentence.

Also, note that the 4th possible regular expression only has 2 parenthesized subpatterns.

ckng’s picture

The patch in #16 looks fine to me.
Please test and review it, set it to RTBC if everything ok, will check back soon.

desrosj’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev

Patched and tested, but after patch I see no phone numbers instead of just +44.

roball’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev

The patch has been created for 6.x, right? So pls test it with the correct branch.

ckng’s picture

Status: Needs review » Needs work

Getting

Notice: Undefined offset: 3 in gb_formatter_default() (line 96 of /var/www/module-dev/sites/all/modules/cck_phone/includes/phone.gb.inc).

The last rule do not return a $matches[3];

([0]*)(1[2-9][0|2-9]\d)(\d{5,6})   # 01xxx [mostly six-digit local numbers] (but not 01x1 codes)

Number used for test
+44 1231 231111

dddbbb’s picture

I'm also getting this problem with UK numbers in the D7 version (Notice: Undefined offset:). Would be happy to test D7 patches if someone can provide them.

nikemen’s picture

subscribing

dddbbb’s picture

@nikemen - Stop subscribing, start following (big blue/grey button at the top right of the page).

thinkyhead’s picture

StatusFileSize
new3.51 KB

Here's a patch for the current 7.x-1.x-dev that does everything in the previous (6.x) patch posted in #16. It seems to properly handle the case mentioned in #20. As an additional enhancement, if for some reason the number is not matched by one of the regexes it simply prepends the country code to the raw $element['number'] value. This at least prevents a blank phone number from coming back, and would be the proper failsafe method.

thinkyhead’s picture

StatusFileSize
new3.08 KB

The array regex doesn't seem to be needed as long as the $matches result is handled properly. This patch supersedes the previous one.

dddbbb’s picture

The patch doesn't seem to work. Part of the problem may be that it's pointing at 'includes/phone.gb.inc' which seems incorrect (the directory is called 'include' not 'includes' - no 's'). Even stripping out the unwanted 's's seems to result in errors.

Any chance or rerolling the patch? I'd do it myslelf if I could get it to work :/

thinkyhead’s picture

Status: Needs work » Needs review
StatusFileSize
new1.62 KB
new1.62 KB
new3.63 KB

@dixhuit, are you sure you read my comment at #24? That was a patch against the 7.x-1.x-dev branch, which I got directly through git. And the 7.x-1.x branch does indeed use the name 'includes' for the included files folder. In fact, I just downloaded and patched the 6.x-1.x-dev branch, and it likewise uses a directory named 'includes.' So, that patch is attached here. For simplicity I've also attached my patched phone.gb.inc files for each branch.

dddbbb’s picture

Oops, I may have been using the latest stable release, rather than the dev branch. WIll check again and feedback.

dddbbb’s picture

Aah. Turns out I was using the 'phone' module (not 'cck_phone'). My bad :/

dddbbb’s picture

Installed cck_phone and sure enough the new phone.gb file seems to fix this issue. Still couldn't get the patch to work but maybe that's just me.

nikemen’s picture

I've tested the file with 7.x-1.x-dev and it works perfectly.

ckng’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Needs review » Fixed

Thanks for the patches, committed to both D6 & D7.

adam_b’s picture

Is this in the 16 Feb dev version? I'm still getting only a partial display (+44-20 7207). In addition, I still can't enter a UK mobile number.

adam_b’s picture

Status: Fixed » Closed (fixed)

Okay, in the 17 Feb dev version (once I'd got rid of #1444442: Fatal error) a regular UK phone number now displays correctly.

But UK mobile numbers don't work at all. As soon as I change the leading number to a 7 (which is the only thing that specifies a mobile number), I get an error:
"70 1234 5678" is not a valid United Kingdom phone number, it should be a 10 digit number like "99 9999 9999", with optional leading "0"

The only way to make it work is to untick the "Enable country level validation" checkbox in the field config.

adam_b’s picture

Status: Closed (fixed) » Fixed

Sorry, didn't mean to change the status...

tebb’s picture

Did I misunderstand?

If as mentioned in #34, this doesn't work for UK mobile numbers, why are we saying it's fixed?

Example:

In the UK: 07912 345678 ==> Internationally: +44 7912 345678

adam_b’s picture

Well, I'd say the original bug mentioned in the title has been fixed, and this issue is long enough - so I've opened a new one for the UK mobile bug at #1450146: UK mobile phone numbers aren't accepted.

tebb’s picture

OK.

Thanks Adam.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

g1smd’s picture

> "70 1234 5678" is not a valid United Kingdom phone number"

This isn't a mobile number. It's a premium rate Personal Number.

UK mobile numbers begin 074, 075, 07624, 077, 078, 079 (and will likely also use 073, 072, and 071 in the future).

Additionally, the module doesn't correctly format UK landline 5+5 (e.g. 015395 44777) or 5+4 (e.g. 016977 3555) numbers. Things get a little more complicated in those Mixed Areas (and in ELNS areas).
Mixed areas are those detailed at: http://www.aa-asterisk.org.uk/index.php/Mixed_areas