How to adjust SMS number prefixes

In this guide we give example routing rules, that show you how you can adjust phone number prefixes with routing rules. If the phone numbers come in various formats from the users, we need to create rules, that adjust each format to make sure that numbers are sent properly to the sms service privider.

Introduction

In our example the SMS service provider will accept a phone number coming in the following format:

+97466781661

The users of the system will use other formats to send the message. Fore example:

66781661 -> +97466781661
0097466781661 -> +97466781661
97466781661 -> +97466781661
+97466781661 -> +97466781661

We want to make sure all of the above formats will be accepted by our sms service provider. In order to achieve this we will create 5 routing rules:

Route 1: Add the "+974" prefix to 8 digit long phone numbers
Route 2: Change the phone numbers starting with "00974" to start with "+974"
Route 3: Change the phone numbers starting with "974" to start with "+974"
Route 4: Leave the phone numbers starting with "+974" and send the sms to the mobile network
Route 5: Anything elso should be sent to the recycle bin

Route 1 / Step 1: Create the route

The first example will add a prefix to the phone number if the phone number is exactl 8 digits long.

Change this: 66781661
To this: +97466781661

You need to create a dedicated route to do this modification. This route needs to match the 8 digit phone numbers, and it needs to modify them to have the +974 prefix.

You can start by clicking on the "Routes" icon in the toolbar. After this specify the "From" connection as "Any_SMS_User" and the "To" connection as "SMPP_Client_1". Leave the mode as "Move".

Figure 1 - Create the route

Route 1 / Step 2: Create a match condition

To make this route match phone numbers exactly 8 digits long, you need to add a "Match condition". The "Match condition" will check the "To address" and if the phone number is exactle 8 digits long the root will go into effect.

Match condition:

/^\d{8}$/

The above codition can be broken down like this:
start the matching: ^
8 digits are coming: \d{8}
end the matching: $

Figure 2 - Match route

Route 1 / Step 3: Create a modifier

After the sms matches this pattern, the modification rule will take effect:

/^(\d{8})$/+974$1/

The above codition can be broken down like this:
change this: ^(\d{8})$
to this: +974$1

Note that the "to this" section contins $1. This means that the first group should be put there. The first group is "(\d{8})". A group is marked by ( ).

Figure 1 -

Route 1 / Step 4: Test the route

To test the system, simply send an SMS to an 8 digit phone number. Note, that after sending the message, when you check the sent items folder, you will see that the "To" phone number was changed to the appropriate format. You have sent the sms to "66781661", but the sms was actually sent to "+97466781661"

Send message to 66781661
Figure 3 - Send message to 66781661

Message sent to +97466781661
Figure 4 - Message sent to +97466781661

The route properties are:

Route name: Route 1
From: Any_SMS_User@localhost
To: SMPP_client_1@localhost
Mode: Move
Match To address: /^\d{8}$/
Modify To address: /^(\d{8})$/+974$1/

The above table contains the settings you need to apply


Route 2. - 00971 prefix to a +971 prefix

The second route will change the 00 prefix to a + sign. In mobile networks the international phone numbers are starting with a + sign, while in classic telephone systems they start with 00.

Change this: 0097466781661
To this: +97466781661
Match condition:
/^00974.*$/

The above codition can be broken down like this:
start the matching: ^
the following digits are: 00974
anthing can come after this: .*
end the matching: $

Modifier:
/^00974(.*)$/+974$1/

The above codition can be broken down like this:
change this: ^00974(.*)$
to this: +974$1

The route properties are:

Route name: Route 2
From: Any_SMS_User@localhost
To: SMPP_client_1@localhost
Mode: Move
Match To address: /^00974.*$/
Modify To address: /^00974(.*)$/+974$1/

The above table contains the settings you need to apply


Route 3. - 971 prefix to a +971 prefix

The routeroute will change add + sign to the phone number. In mobile networks the international phone numbers are starting with a + sign, unless the + sign is added the number will be treated as a local number.

Change this: 97466781661
To this: +97466781661
Match condition:
/^974.*$/

The above codition can be broken down like this:
start the matching: ^
the following digits are: 974
anthing can come after this: .*
end the matching: $

Modifier:
/^974(.*)$/+974$1/

The above codition can be broken down like this:
change this: ^974(.*)$
to this: +974$1

The route properties are:

Route name: Route 3
From: Any_SMS_User@localhost
To: SMPP_client_1@localhost
Mode: Move
Match To address: /^974.*$/
Modify To address: /^974(.*)$/+974$1/

The above table contains the settings you need to apply


Route 4. - +971 prefix to a +971 prefix (let the properly formatted numbers through)

The forth route will simply match the properly formatted phone number and will let the SMS through without modification.

Match this: 97466781661
Match condition:
/^[+]974.*$/

The above codition can be broken down like this:
start the matching: ^
the following digit is: +
the following digits are: 974
anthing can come after this: .*
end the matching: $

Note that the + sign was put in brackets: [+]. This is because the + sign is a special character in the regular expression syntax.

Modifier:
Leave empty

If the phone number is formatted properly no modificatoin is needed

The route properties are:

Route name: Route 4
From: Any_SMS_User@localhost
To: SMPP_client_1@localhost
Mode: Move
Match To address: /^[+]974.*$/
Modify To address:

The above table contains the settings you need to apply


Route 5. - Move anything else to the recycle bin

Our final route will move any phone numbers that are not matched by any of the routing conditions above to the recycle bin.

Match: Anything
No change
Route to: Recycle bin

Route name: Route 5
From: Any_SMS_User@localhost
To: SMPP_client_1@localhost
Mode: Drop
Match To address:
Modify To address:

The above table contains the settings you need to apply

The final routing table

Your final routing table will look like this:

Route name From Match Modify Mode To
Route 1 Any_SMS_User@localhost /^\d{8}$/ /^(\d{8})$/+974$1/ Move SMPP_client_1@localhost
Route 2 Any_SMS_User@localhost /^00974.*$/ /^00974(.*)$/+974$1/ Move SMPP_client_1@localhost
Route 3 Any_SMS_User@localhost /^974.*$/ /^974(.*)$/+974$1/ Move SMPP_client_1@localhost
Route 4 Any_SMS_User@localhost /^[+]974.*$/ Move SMPP_client_1@localhost
Route 5 Any_SMS_User@localhost Drop

More information