Phone Number Normalisation

Ajdin Mustafić - Mar 28 '22 - - Dev Community

The phone number normalisation is used to translate a phone number into a standard form.

For example, there is E.164 international standard which defines format as "[+] [country code] [subscriber number including area code] and can have a maximum of fifteen digits". However, we rarely save numbers, especially domestic ones, in this exact format.

This can be a huge problem if you wanted to allow your users to import their mobile phone contacts into your application. The users can have the phone number, in their phone contacts, entered with or without country code, or can enter country codes like 00385 or +385, etc. So if you didn't have the phone number normalisation, these two numbers 00385991234567 and +385991234567 would be imported as two different phone numbers for the same contact even though when calling, they are the same, just written in different format standards.

We have a similar challenge on one of our projects, so our first step was to research, what should be covered and what others cover when they do the phone number normalisation.

One of my outputs were the test cases that are covered by Whatsapp:

  1. I can't contact a foreign mobile number without a country code - For example, if your phone number is from Croatia and you saved a contact with a mobile phone number from Austria, without the country code, Whatsapp will not recognize it as existing.
  2. I can contact domestic mobile number without country code - For example, if your phone number is from Croatia and you saved a contact with a mobile phone number from Croatia, without the country code, Whatsapp will recognize it as it is (existing).
  3. I can contact a foreign mobile number with "00" country code - For example, if your phone number is from Croatia and you saved a contact with a mobile phone number from Austria, with the 0043 country code standard, Whatsapp will recognize it as existing.
  4. I can contact a foreign mobile number with a "+" country code - For example, if your phone number is from Croatia and you saved a contact with a mobile phone number from Austria, with the +43 country code standard, Whatsapp will recognize it.
  5. I can contact a foreign mobile number with "+" country code and 0 before the mobile prefix - For example, save the foreign phone number in your contacts with "+" country code and zero before the mobile operator prefix (+385 0 99 1234567). Whatsapp will recognize and normalise the number to +385 99 1234567.
  6. I can't contact a foreign mobile number with "00" country code and 0 before mobile prefix - For example, save the foreign phone number in your contacts with "00385" country code and zero before mobile prefix (+385 0 99 1234567). Whatsapp will not recognize the number as the same as +385991234567.
  7. I can't contact domestic mobile number with "00" country code and 0 before mobile prefix - For example, save the domestic phone number in your contacts with "00385" country code and zero before mobile prefix (+385 0 99 1234567). Whatsapp will not recognize the number as the same as +385991234567.

Handling phone numbers, especially without normalisation can create a real mess in your application because many users in different countries use different phone number standards to create their contacts.

Feel free to share your experience and your test case examples in the comments section.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player