Wednesday, December 5, 2012

Localized UK Dialing Rules for the Optimizer

Using data from a number of web sources and some helpful users, I've been able to create customized Lync dialing rules for over 30 countries worldwide and made them available to all via the Lync Dialing Rule Optimizer.  These customized dialing rules account for country-specific dialing patterns for local, national, international, toll-free, mobile, premium and service numbers.

However, true localized dialing rules have been out of reach for countries other than those in North America until now.  For all non-North American countries, I have been forced to create generic dialing patterns for local numbers simply because I don't have access to any source of local dialing rule data.  This isn't generally a problem because most local dialing rules are different enough from other patterns that conflicts are rare.  For example,  a local dialing rule for a country might specify that the number start with digits 2-9 and are between 5 and 6 digits in length.  As long as there aren't any other dialing patterns in that country that use that same pattern (ie national, international, mobile, service, toll-free or premium), there won't be a problem.  I try to make sure that is the case for all dialing rules created for the Optimizer, but it is sometimes difficult.

The United Kingdom has more than 60 different local dialing rules. Local numbers can be 4 to 8 digits in length and area codes have from 2 to 5 digits. Some 41 area codes have mixed length numbers where some numbers have a total 10 digits and others have only 9. In some area codes the local number cannot begin with certain digits, or certain digits will not come into use for many decades.  The generic UK local dialing rule used by the Optimizer tries to account for all these in a single regular expression, but obviously some generalizations had to be made.

Enter Ian Galpin of the UK.  Ian has made it a personal mission to ensure that the UK has a complete set of dialing rules written as regular expressions.   Over the past year, he's helped me ensure the regex for UK dialing rules are correct.  He's also created a localized set of dialing rules for every area code in the UK as an XML file along with a list of all the area codes used in the UK.  He's done this to help various telephony vendors create the appropriate rulesets for PBX deployments. I've been able to incorporate that into the Lync Dialing Rule Optimizer, so that UK users now have true customized local dialing rules for Lync that will differ depending on which area code you select in the Optimizer.

I've modified the Optimizer code to be able to use local dialing rules for other countries if available.  If anybody can point me to a similar source as provided by Ian for other countries, it would be greatly appreciated.

1 comment:

  1. Yes, the UK is difficult to cater for. There's a lot of variations and the official data has several errors ready to trip the unwary.

    I created a page with more detailed information on the local dialling rules here: Local dialling rules for GB telephone numbers and the XML file is based on that.


    The remainder of the patterns for the UK should look something like this:

    Toll free:
    ^0(80(0\d{6,7}|8\d{7}|01111)|500\d{6})$
    ^\+44(80(0\d{6,7}|8\d{7}|01111)|500\d{6})$

    Premium rate:
    ^0(9[018]\d{8}|87[123]\d{7}|70\d{8})$
    ^\+44(9[018]\d{8}|87[123]\d{7}|70\d{8})$
    or
    ^0((9[018]\d|87[123]|70\d)\d{7})$
    ^\+44((9[018]\d|87[123]|70\d)\d{7})$

    National:
    ^0(1[1-9]\d{7,8}|2[03489]\d{8}|3[0347]\d{8}|5[56]\d{8}|8((4[2-5]|70)\d{7}|45464\d))(\D+\d+)?$
    ^\+44(1[1-9]\d{7,8}|2[03489]\d{8}|3[0347]\d{8}|5[56]\d{8}|8((4[2-5]|70)\d{7}|45464\d))$
    or
    ^0(1[1-9]\d{7,8}|(2[03489]|3[0347]|5[56])\d{8}|8((4[2-5]|70)\d{7}|45464\d))(\D+\d+)?$
    ^\+44(1[1-9]\d{7,8}|(2[03489]|3[0347]|5[56])\d{8}|8((4[2-5]|70)\d{7}|45464\d))$

    Mobile:
    ^0(7([1-57-9]\d{8}|624\d{6}))$
    ^\+44(7([1-57-9]\d{8}|624\d{6}))$
    or
    ^0(7([1-57-9]\d{2}|624)\d{6})$
    ^\+44(7([1-57-9]\d{2}|624)\d{6})$

    with the outermost parentheses allowing the RegEx pattern to match and then capture the national significant number as $1.

    There's always multiple ways to optimise RegEx patterns and it soon becomes a battle between being readable (and therefore easy to maintain) and being efficient.

    ReplyDelete

Note: Only a member of this blog may post a comment.