Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When using the E.123 option for validating free-form international numbers, I ran into a few problems with the phone.int.inc file, which are addressed in the patch.
This patch fixes, "is not a valid Italian phone number".
- The default error message mentioned Italy, which is clearly incorrect.
- The Regex for finding the country code needed the code to be separated from the rest of the number, generally with a space, or it couldn't be found. The attached patch goes through the known country codes until it finds one (starting with the longest, first), which is essentially how the PSTN does it.
Comment | File | Size | Author |
---|---|---|---|
#19 | interdiff.patch | 209 bytes | lambic |
#16 | phone-international-2108707-16.patch | 11.92 KB | lambic |
#15 | phone-international-2108707-15.patch | 11.92 KB | lambic |
#7 | phone-international-2108707-7.patch | 11.89 KB | roderik |
#5 | phone-international-2108707-4.patch | 11.17 KB | bbinkovitz |
Comments
Comment #0.0
Greg BoggsAdded error message to description.
Comment #1
MiroslavBanov CreditAttribution: MiroslavBanov commentedPatch did not apply to current 7.x-1.x, rerolled the patch with a small change:
< - drupal_set_message('langue cc = ' . $cc, 'error');
> - //drupal_set_message('langue cc = ' . $cc, 'error');
Note that I do not want to take credit for this contribution.
Comment #2
ingomueller.net CreditAttribution: ingomueller.net commentedI just ran into the same problem. Thanks a lot for the patch, it seems to work fine for me now! Without this patch, this module seems hardly usable (with international numbers), since it is very unobvious for a user that the space is needed and the error message leads into a totally wrong direction. It'd be great if the patch could be integrated.
Comment #3
extect CreditAttribution: extect commentedPatch is working absolute fine for me as well.
Setting this to RTBC so that it'll hopefully be committed soon.
Comment #4
bbinkovitz CreditAttribution: bbinkovitz commentedPrevious patch didn't apply for me, and introduced weird whitespace, so I re-rolled it.
Comment #5
bbinkovitz CreditAttribution: bbinkovitz commentedComment #6
bradjones1FYI, the patch rolled in #1 currently applies to -dev; the original patch and the one in #5 do not. This is still RTBC.
Comment #7
roderikI'm tempted to set this back to Needs Review, because of #2.
Notes and discoveries:
#1
the huge regex isn't necessary. I'm pretty sure a simpler solution using substr will save memory (and possibly CPU).
#2
the array in phone_country_code_convert() has duplicate keys, so that needs fixing. I placed 'us' before 'ca' so 'us' is returned for input value 1, because that is also the behavior from before the patch. 'au' is now returned for 61 and 'it' for 39 (instead of 'cc' and 'va' respectively) because that just seems sensible.
Note that means that phone.ca.inc is never used. But that seems to be the case already!?
That's why I didn't fix this (this can be done by someone else if they want to) - I only provided clear comments.
#3
the patch makes numbers actually be validated. Before the patch, TRUE is almost always returned, because the module_load_include() is wrong, so $valid_phone_function is not called. (Unless it was loaded already.)
#4
When we're starting to validate things anyway... I changed the 'else' case to not only return TRUE, but check (using format_int_phone_number()) whether an international dialing code is present in the area code, and return FALSE if not.
(If this check isn't done, then format_int_phone_number() will still delete figures without warning you, leading to bugs like #1563692: format_int_phone_number() fails to use the appropriate country formatter and strips bits out of valid Swedish phone numbers.)
Comment #8
roderik.
Comment #9
yoruvo CreditAttribution: yoruvo commentedEDIT:
Scratch that, I was testing on the wrong system. The patch seems to work; I no longer get an Italian-specific error message when putting in random garbage. I haven't tested further, but I can confirm that part works fine, now.
However the string is missing a period at the end of the sentence.
Comment #10
gumdal CreditAttribution: gumdal commentedI am using 7.x-1.0-beta1 version of Phone module, can I use the patch against this beta version?
Also, which patch to use? Confused between #1, #5 and #7?
Thanks.
Comment #11
bradjones1@gumdal - Generally you want to apply patches you find in the issue queues to the -dev version. So in this case you could do :
Comment #12
joelpittetHow about not using Country Codes? US and Canada are using north american standards, should there be one file for them both. NA/North America.
Comment #13
HydroZ CreditAttribution: HydroZ commentedPatch #7 did fix the wrong validation error.
Comment #14
DamienMcKennaI think this approach is fine, it's better to work from something tangible as country codes that might come up in other scenarios.
Comment #15
lambic CreditAttribution: lambic at New/Mode commentedI made a small modification to patch 7 so that in the case where we don't have a specific validation function for a given country then we at least check that the number is more than 5 digits. Patch attached.
Comment #16
lambic CreditAttribution: lambic at New/Mode commentedFixed patch with the correct variable name
Comment #17
DamienMcKennaComment #18
joelpittet@lambic this was RTBC already, could you provide an interdiff with your change so we can review the change, hopefully worth the status change?
See https://www.drupal.org/documentation/git/interdiff
Comment #19
lambic CreditAttribution: lambic at New/Mode commentedComment #20
joelpittetThanks for the interdiff. Why 5 digits? Isn't
911
or411
valid north american phone numbers?Comment #21
lambic CreditAttribution: lambic at New/Mode commentedThis is in international validation, so only happens if there's no country specific validation. In theory for countries with a single digit country code and no country specific validation, 3 digit phone numbers would fail, we could reduce the check to 4 digits to cover that use case, or make the number of digits settable via a variable.
Comment #22
shenzhuxi CreditAttribution: shenzhuxi commentedAll the number without country code will call valid_us_phone_number and include/phone.us.inc file doesn't exist.