Icon

Process Telephone Numbers

Example of processing telephone numbers to obtain the country code.

This workflow demonstrates parsing of telephone numbers, but keep in mind that the exact approach is country-specific and so will require configuration and may require alteration for non-UK territories, although hopefully the configuration will generally suffice.

The workflow was written as a response to the following Forum question:
https://forum.knime.com/t/country-codes-extract-from-given-phone-numbers/48529

This workflow also demonstrates the use of my Join LIKE component, which is used here to wildcard-join to the international dialling codes list which is contained within a CSV file inside this component.

The International code list is believed to be correct, but is not guaranteed. Check it if you wish to use it and complete accuracy is important to you.

The source for this CSV list was a json file downloaded from:
https://gist.github.com/anubhavshrimal/75f6183458db8c453306f93521e93d37



Workflow to parse a list of telephone numbers, and determine the InternationalSubscriber Dialling (ISD) Code for each.This workflow requires "local" customisation in the form of the Variable Creator. Thedemo here is customised for UK as the "local" country.Any numbers listed that are in local format will be treated as belonging to the localcountry. Local country config:default_country_codeThe country code for the local country (+44 )default_international_dial_removalRegex to remove the local international dialling prefix. This isthe code that is entered in the default country in order toindicate that what follows is an international number. This isthe numeric equivalent of entering the + symbol. In the UK, the international prefix is 00, so the removalconfigured here is ^00(.*) which means remove 00 if present at the start of the numberand keep the remaindernon-international-regexRegex pattern describing a non-international number (i.e. anational number in the default country)In the UK, a national number is identified as having a prefix ofa single 0. NB a prefix of 00 would indicate an internationalnumber:^0[1-9]+[0-9]+This means a number starting with a single zero followed byat least one non-zero followed by at least one other digit.Technically we could define the full number of digits accordingto the pattern, but we'll keep it relatively simple. List of internationaldialling codesList of dummy telephone numbersLocal Defaults(valid for UK.Change for other territories)Treat anything not startingwith a single zeroas a country codeTHIS RULE COULD VARYFOR NON-UK LISTApply defaultcountry codewhere missingApply + where missing oninternational numbersRemove any non-numericsRemove defaultintertionaldialling prefixAdd wildcardto assist withsearchingLIKEjoin on dialing codewith wildcardCOMPONENTused as KNIMEdoesn't provide "LIKE"joins as standard nodes. There are some limitations indata types this component can handle so it isused minimally for matching stringsThere can be more thanone territory for a given codeand we just want a distinct listof codesJust the DiallingCode and country namecolumnInternationalDiallingCodeJoin back to countriesto get possible countries/territories for the codeThere can be more thanone territory for a given codeand we just want a distinct listof codesDetermine which numbersare internationalnumbers[Used here like amuch more flexible Rule Engine]CSV Reader Excel Reader Variable Creator Rule Engine String Manipulation String Manipulation String Replacer String Replacer String Manipulation Join Like DuplicateRow Filter Column Filter Column Rename Joiner GroupBy String Manipulation Workflow to parse a list of telephone numbers, and determine the InternationalSubscriber Dialling (ISD) Code for each.This workflow requires "local" customisation in the form of the Variable Creator. Thedemo here is customised for UK as the "local" country.Any numbers listed that are in local format will be treated as belonging to the localcountry. Local country config:default_country_codeThe country code for the local country (+44 )default_international_dial_removalRegex to remove the local international dialling prefix. This isthe code that is entered in the default country in order toindicate that what follows is an international number. This isthe numeric equivalent of entering the + symbol. In the UK, the international prefix is 00, so the removalconfigured here is ^00(.*) which means remove 00 if present at the start of the numberand keep the remaindernon-international-regexRegex pattern describing a non-international number (i.e. anational number in the default country)In the UK, a national number is identified as having a prefix ofa single 0. NB a prefix of 00 would indicate an internationalnumber:^0[1-9]+[0-9]+This means a number starting with a single zero followed byat least one non-zero followed by at least one other digit.Technically we could define the full number of digits accordingto the pattern, but we'll keep it relatively simple. List of internationaldialling codesList of dummy telephone numbersLocal Defaults(valid for UK.Change for other territories)Treat anything not startingwith a single zeroas a country codeTHIS RULE COULD VARYFOR NON-UK LISTApply defaultcountry codewhere missingApply + where missing oninternational numbersRemove any non-numericsRemove defaultintertionaldialling prefixAdd wildcardto assist withsearchingLIKEjoin on dialing codewith wildcardCOMPONENTused as KNIMEdoesn't provide "LIKE"joins as standard nodes. There are some limitations indata types this component can handle so it isused minimally for matching stringsThere can be more thanone territory for a given codeand we just want a distinct listof codesJust the DiallingCode and country namecolumnInternationalDiallingCodeJoin back to countriesto get possible countries/territories for the codeThere can be more thanone territory for a given codeand we just want a distinct listof codesDetermine which numbersare internationalnumbers[Used here like amuch more flexible Rule Engine]CSV Reader Excel Reader Variable Creator Rule Engine String Manipulation String Manipulation String Replacer String Replacer String Manipulation Join Like DuplicateRow Filter Column Filter Column Rename Joiner GroupBy String Manipulation

Nodes

Extensions

Links