python-phonenumbers icon indicating copy to clipboard operation
python-phonenumbers copied to clipboard

whatsapp api uses 13 digit format for mexico, phonenumber does not recognize it

Open joseponzo opened this issue 10 months ago • 1 comments

For Mexico, WhatsApp API sends (webhook) you a message with the 13-digit number format, starting with +521. But PhoneNumber only recognizes the 12-digit format +52. It is a native feature of WhatsApp API. Just for them, it is necessary to accept both options for Mexico. regards

joseponzo avatar Feb 28 '25 02:02 joseponzo

Could you give an example of a specific number and Python library call that gives the wrong result?

Also, can you confirm that the Python code gives a different result than the upstream Java code?

daviddrysdale avatar Feb 28 '25 12:02 daviddrysdale

Hi, any update on this ticket? example of phone numbers failing to validate (whatsapp phone number): is_valid_phone(parse("+5215541637145")) Thanks so much

anotine10 avatar Jul 16 '25 09:07 anotine10

The Python library gives the same results as the upstream library:

./appspot.py  -n "+5215541637145"


Phone Number entered: +5215541637145
Default country entered: None
Language entered: en

## Parsing result (parse(keep_raw_input=True))
country_code                   : 52
national_number                : 15541637145
extension                      : 
country_code_source            : FROM_NUMBER_WITH_PLUS_SIGN
italian_leading_zero           : 
number_of_leading_zeros        : 
raw_input                      : +5215541637145
preferred_domestic_carrier_code: 

## Validation Results
Result from isPossibleNumber()          : False
Result from isPossibleNumberWithReason(): TOO_LONG
Note: Numbers that are not possible have type UNKNOWN, an unknown region, and are considered invalid.

## Short Number Results
Result from isPossibleShortNumber(): False

## Formatting Results
E164 format                                            : invalid
Original format                                        : +5215541637145
National format                                        : 15541637145
International format                                   : invalid
Out-of-country format from US                          : invalid
Out-of-country format from CH                          : invalid
Format number for mobile dialing (calling from US)     : invalid
Format for national dialing with preferred carrier code: invalid
   and empty fallback carrier code

## AsYouTypeFormatter Results
Char entered '+' Output: +
Char entered '5' Output: +5
Char entered '2' Output: +52 
Char entered '1' Output: +52 1
Char entered '5' Output: +52 15
Char entered '5' Output: +52155
Char entered '4' Output: +521554
Char entered '1' Output: +5215541
Char entered '6' Output: +52155416
Char entered '3' Output: +521554163
Char entered '7' Output: +5215541637
Char entered '1' Output: +52155416371
Char entered '4' Output: +521554163714
Char entered '5' Output: +5215541637145

Python library version: 9.0.9

Compare with: https://libphonenumber.appspot.com/phonenumberparser?number=%2B5215541637145&country=ZZ

daviddrysdale avatar Jul 16 '25 09:07 daviddrysdale

Here's some context on the legacy phone number format, deprecated since August 2020: https://www.sent.dm/resources/mx

D-stefaang avatar Oct 14 '25 16:10 D-stefaang