Country Codes extract from given phone numbers

Hi Team Members,

I have a list of phone number from different countries where I have to get the country code and the country from given phone numbers. Does anyone how to do this?


Thank you in advance

KNIME HELP.xlsx (9.9 KB)

Hi Psycho,

Some of these numbers do not contain a country prefix, so how should that work?

For the ones starting with +…, you could maintain and use a lookup table, e.g. +49 > DE.



This is how the data extract looks alike qqilihq. Shall I add a prefix + for all?

If a country code is not there, then you simply don’t have the information which you’re looking for.

Maybe an assumption such as “if no country prefix with + is given, just assume country X” combined with the lookup table will work?

Assuming the “+” will mark the numbers that have international codes. ( +xxx)
The regex split node with the expression in bellow will do the job

I would not assume that the international code is +xxx

North American (NA and Canada) usual format is +1-regional code-phone number. For example:

Locally, the phone number is: 123-456-7890

Internationally, the phone number is: +1-123-456-7890


Yes. I it was a naïve assumption

I was thinking in PT code +351 , for the one you described could be solved by the expression (^+.?\W).*
in the same node followed by a string replacer. ( image bellow)

Any how , just check the international code for UK is +44 . SO IMO the problem has no solution unless we have another field containing the country witch belongs the number .


Hi @psycho ,
I don’t know if you are still seeking an answer but I thought I would share this. As has been stated by @Adrix , your question (as asked) is unsolvable. Not all of the numbers you have listed contain country codes. Your earlier statement to @qqilihq

did amuse me though (sorry!). If it is true, it tells me that you need to find out why your data source is supplying you with rubbish data :wink: The numbers that you have listed are clearly not all valid telephone numbers. And that’s mostly ok, because they shouldn’t be actual VALID number that are being posted here anyway. The only thing is though, when the format of the number is essential to demonstrating how to perform the task, then ideally whilst it should be dummy data, it should still be “correctly formatted” dummy data.

Now on the face of it, I would say that they look a bit like UK numbers, except that then the 1334 number would be invalid and in fact none of them are long enough to be UK numbers as the UK standardised on 11 digits for both national and mobile numbers a few years back, and even the +44 number is 1 digit too short when you remove the +44 prefix and add back the UK 0 National STD code prefix. (Back to my point about correct formatting)

However, let’s assume that the data set is exactly what it appears to be (i.e. dummy data), and for the sake of my demo, they are UK numbers unless otherwise specified.

In order to parse telephone numbers and obtain country codes from them you need the following information:
(1) A list of all available international dialling codes
(2) Knowledge of local telephone number formats
(3) Knowledge of any additional prefix codes that can be used for international dialling,
(4) … well… some other stuff could be added depending on how robust you want the solution to be, but I’ll go with these three for demo purposes.

Taking each of those…

(1) I was surprised at not being able to quickly find an easy-to-download list (e.g. csv) of international codes. I found lots of promising links, and html tables, but little in the way of easily usable downloads. Maybe that was just me having a bad-search-day. Anyway I finally settled for the following json file:

which I downloaded and extracted what I needed and turned into a CSV file.

(2) Local telephone number formats are important. In the UK, all national telephone numbers begin with a single 0 followed by a non-zero followed by a series of other digits.

(3) Knowledge of other prefix codes. - in the UK, and many other countries, 00 is a standard international access prefix which is the equivalent of pressing + on mobiles or other suitably equipped telephones. So, if the number starts 00 it means that what follows is an international dialling code and what follows that is the national number in the territory represented by that dialling code.

(4) Other things to note: My list above is not exhaustive. We have other codes in the UK such as 100 to call the operator, 118nnn for directory services, and other special numbers starting with a 1, and then there is the emergency services (i,e, 999, equivalent of 911) for example. I’m not taking any of that into account with this list, and they would need special handling.

As noted, I am going to do this demo from the point of view of this being a UK list, so apologies if it is not but hopefully it will demonstrate the point anyway and can be adapted once you have found the required info to cover the 3-4 point list above.

The international dialling code for calling the UK is +44. So anything in the list not recognised as an international number, will be treated as being a +44 number. There is also a standard that when dialling a country internationally, any preceding zero in the national number being dialled should be dropped. So if the telephone number in your list 0203456789 were a valid UK number, then internationally it would be +44203456789 (i.e. the prefix-0 has been removed).

Because all UK national numbers begin with a 0, anything in your list not starting with a zero will be treated as an international number (and I’ll just assume that for those, the + has been inadvertently missed off, so I will add it). In summary anything not identified as local to me (UK) will have a + appended as a prefix if not already present.

The numbers identified as local UK numbers will be converted to international numbers, and with all that put together we will get the following list:

After that, we can try to match the numbers with the international dialling codes list.

The thing about telephone numbers is that they come from a pre-electronic age. As such numbers were handled by mechanical equipment and so as soon as a digit is dialled, the routing for that number becomes fixed, irrespective of the digits that follows.

Now this may seem like abstract knowledge, but it is actually very useful to know. It means that any range of numbers that defines a destination cannot be further subdivided to a completely different destination.

e.g. Because the international code for US/Canada is +1, this completely removes the possibility that any other international code can start with a 1. The 1 range has been completely taken by US/Canada.
Likewise +44 is UK (and UK-territories [Guernsey, Isle of Man, Jersey, United Kingdom] ). As such no other country can have a dialling code beginning +44.

With that knowledge in mind, we can easily wild-card match the list of dialling codes with the list of telephone numbers we now have. We don’t have to worry about lengths of the actual codes. We don’t have to worry that +44 would match UK but +442 might match somewhere else. It can’t. If a number starts +44 we know it is UK. It is good to understand your data!

I have uploaded a demo workflow to the hub. You would need to configure it, and possibly modify it (remove/change my assumptions) to make it work in a different local country, but hopefully it gives an idea about how telephone number matching can be made to work.

For the wild-card matching the standard joiner can’t be used, so this also serves to demo another component, the “Join Like” component that you can find on the hub at

Once we have that, we can join the international dialling codes back to the original csv file and pick up the related country/territory information should we wish.

The demo workflow can be found here:


your component library is amazing. I sometimes wonder whether there is still a topic where not already a @takbb ’ components solution exists :wink:

1 Like

Lol @Daniel_Weikert … I wonder if any of them actually work… :joy:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.