Friday, January 4, 2013

Blocking International Calls to Specific Countries in Lync

A question that often comes up in my travels is that Lync administrators want an easy way to allow users to dial internationally but exclude specific countries for some reason.

This is very easy to accomplish once you understand the ins and outs of regular expressions, and assuming you follow all my best practices regarding number normalization, and Enterprise Voice setup.  To summarize, every number a user enters in Lync should be normalized to E.164 standards, which starts with a + followed by the country code, then the area/city code and finally the local subscriber number.  A Canadian example (country code 1) would be +14165551111.  A UK example (country code 44) would be +442033334444.  If you use the Lync Dialing Rule Optimizer to create your Enterprise Voice configuration, you'll be all set.

When all numbers are normalized to E.164, and you already have separate usages and routes for local, national and international calls, it makes it very easy to design regular expressions that meet any specific criteria required by your business.

Say your company is based in North America, and is required to block international calls to Iran (98) and North Korea (850).  The Lync Dialing Rule Optimizer routing rule for international calls is this:

This rule allows any number that doesn't start with a 0 or 1 to be routed out. Only North American countries (US/Canada and some Caribbean countries) use the country code 1.  All other country codes start with the digits 2-9.  So essentially, this rule allows calls to any international destination.

To block calls to Iran and North Korea, modify the rule to look like this (new stuff highlighted in yellow):

This will allow any number starting with 2-9, but excludes numbers that start with 98 or 850 as required.

If you're not in North America and used the Lync Dialing Rule Optimizer to create your Enterprise Voice setup, your international rule looks a little different, because we want to make sure that North American numbers are formatted correctly (as highlighted in blue), while making sure that it does not try to route national numbers as international (using UK +44 as an example, shown in green):

To block calls to Iran and North Korea using this example, modify the rule as follows (new stuff highlighted in yellow again):

Now, anybody who tries to dial a number in Iran or North Korea will be met with a notice that the call couldn't be completed.

This method is pretty granular as you could create separate routes to block countries selectively or for a specific group of users.  If you want to just block those numbers globally, you can use Unassigned Numbers to provide an announcement to users that those numbers are not allowed to be dialled. The only downside to that method is that you need to know in advance how long phone numbers are in the country you want to block.

Happy Enterprise Voicing everyone!


  1. I think, but I am not sure, that


    should be


    You have already added those extra brackets in the other example patterns.

  2. I am implementing your dial plans for Teams. For international calling, I want to create a block list for a long list of countries (124) we never want to call. It is too long to fit into a single rule, so I can't just expand the International rule. Do you have advice on how to do this?

    1. Below is sample regex that contains every valid country code in the world. With a bit of work, you should be able to modify it to only include the countries you want to allow dialing to:


    2. Thanks for this! I had been having the thought since I wrote my post, and now further since seeing your reply, that rather than implementing a block list, it may be easier to make an allow list. For example, allowing the Microsoft "Zone A" countries only. Also, I will need to combine that with your NA Premium rate filtering [(1(?!(900|976)] to become the new International rules.

    3. How does this look for a Microsoft "Zone A" international dialing list, with NA Premium numbers blocked? I did positive tests for all countries on, and negative tests against a couple dozen countries and all passed.


      I may extend that list slightly yet, for example, Costa Rica, where Microsoft itself has support people, is not on the Zone A list.

    4. Yep, that looks good! I don't know which specific countries are in Zone A, but I think you've got a good handle on it.

    5. I just realized that does not capture clamping the NANPA countries. Here is a version that clamps the NANPA countries and Premium numbers, except for Canada, the US and Puerto Rico. I am not sure if this will fit in Microsoft Teams though - it may be too long.


      And here is a version with Costa Rica and Israel added:

    6. Here are my final versions of this. I wrote my own NANPA filtering previously rather than using yours, and I missed a country or two as a result:

      # Microsoft Zone A countries only allowed for International Dialing

      # Microsoft Zone A countries only plus:
      # Costa Rica (506)
      # Israel (972)

      # Microsoft Zone A countries only plus:
      # Costa Rica (506) & Israel (972)
      # And less:
      # Russia (7), Romania (40), Poland (48), Malaysia (60), Bulgaria (359), Estonia (372), Slovenia (386)