Phone Number translations
Rules are provided as Regular Expressions. To be more accurate: The Javascript implementation of Regular Expressions.
A good way to start is by reading this document: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
Nevertheless, creating complex Regular Expressions is often cumbersome. Therefore we added extra syntax to make configuration as easy as possible.
The figure below shows the general syntax of a phone number translation rule:
Predicate
The predicate is used to define an interval defining the length of the incoming number to match.
The predicate above defines that all numbers with a length between 7 and 11 characters (including edges + spaces) match.
Predicates always match the original length of the number. This helps in simplifying the configuration by reducing the risk of colliding rules for internal / external numbers.
Pattern
The Pattern defines the format of the number to match.
The pattern above matches all non-numeric characters.
Replacement
The replacement defines the final format of the number. If characters / digits need to be added, which were not originally present, this is the place to do it.
The replacement is the last step when building the number. Based on the pattern output, the replacement builds up the new number.
Example 1: Swiss E164 format
The following example shows how to translate the number 031 91 75 200
to the Swiss E164 format +41 31 917 52 00
.
This example uses two translation rules (1. and 2.)
Please Note: The Predicate matches the original number, but the Pattern matches the result of the previous rule.
1st Rule
It removes any character except digits, for numbers between 1
and 17
characters in length.
2nd Rule
It applies to numbers which are exactly 13 characters long. 031 91 75 200
matches and therefore the rule gets applied. The pattern specifies that the number must start with a group of one digit (\d{1})
, followed by a group of two digits (\d{2})
followed by a group of three digits (\d{3})
and so on.
The selector then accesses the pattern groups to define the new number string. $2
references the first (\d{2})
and therefore contains 31
.
Example 2: US E164 format
The following example shows how to transfer a number received from CC, in the format of +14693150217
to the US E164 format +1 469 315 0217
.
Please Note: The Predicate matches the original number, but the Pattern matches the result of the previous rule.
1st Rule
- It applies to numbers with 1 to 17 characters so a rule with the predicate
[1,17]
is applied. - It removes any character except + and digits.
2nd Rule
- This number is exactly 12 characters long, so a rule with the predicate
[12,12]
is applied. (\+1)
says that the number must start with+1
. If the number is 12 characters long, but does not start with a+1
, the rule is canceled and nothing is changed.(\d{3})
says that+1
must be followed by 3 digits.(\d{3})
says that the last 3 digits must be followed by another 3 digits.(\d{4})
says that the last 3 digits must be followed by 4 digits.
If any of this does not match, the number will not be changed.
So all of the rules apply for +14693150217
. Therefore the number is changed by $1 $2 $3 $4
:
$1
refers to the group(\+1)
, the number to send to Dynamics looks like+1
$2
refers to the first of the two(\d{3})
, the number to send to Dynamics looks like+1 469
$3
refers to the second of the two(\d{3})
, the number to send to Dynamics looks like+1 469 315
$4
refers to the last group(\d{4})
, the number to send to Dynamics looks like+1 469 315 0217
The spaces in the replacement part of the rule $1 $2 $3 $4
are used directly.
So if you would use $1-$2-$3-$4
the number would get translated to: +1-469-315-0217
And you are also allowed to remove groups:
[12, 12]->(\+1)(\d{3})(\d{3})(\d{4})->$2 $3 $4
will get translated to: 469 315 0217
[12, 12]->(\+1)(\d{3})(\d{3})(\d{4})->$3 $4
will get translated to: 315 0217
So it is also possible to convert an international US number to a local one
like: [12, 12]->(\+1)(\d{3})(\d{3})(\d{4})->($2) $3-$4
Then the incoming number +14693150217
will get translated to: (469) 315-0217
Example 3: DE E164 format
The following example shows how to transfer a number received from CC, in the format of +491515555531
to the German E164 format +49 151 5555 531
.
Please Note: The Predicate matches the original number, but the Pattern matches the result of the previous rule.
1st Rule
- It applies to numbers with 1 to 17 characters so a rule with the predicate
[1,17]
is applied. - It removes any character except + and digits.
2nd Rule
- This number is exactly 13 characters long, so a rule with the predicate
[13,13]
is applied. (\+49)
says that the number must start with+49
. If the number is13
characters long, but does not start with a+49
, the rule is canceled and nothing will be changed.(\d{3})
says that+49
must be followed by 3 digits(\d{4})
says that the last 3 digits must be followed by 4 digits(\d{3})
says that the last 4 digits must be followed by 3 digits
If any of this does not match, the number will not be changed.
So all of the rules apply for +491515555531
. Therefore the number is changed by $1 $2 $3 $4
:
$1
refers to the group(\+49)
, the number to send to Dynamics looks like+49
$2
refers to the first of the two(\d{3})
, the number to send to Dynamics looks like+49 151
$3
refers to the second of the two(\d{4})
, the number to send to Dynamics looks like+49 151 5555
$4
refers to the last group(\d{3})
, the number to send to Dynamics looks like+49 151 5555 531
The same applies as for rule one. You can use the replacement part $1 $2 $3 $4
to choose what to use from the number.
Rule examples
Add
Description | Rule |
---|---|
Adds +1 | [1,99]->(.+)->+1$1 |
Adds +41 | [1,99]->(.+)->+41$1 |
Adds +49 | [1,99]->(.+)->+49$1 |
Adds +91 | [1,99]->(.+)->+91$1 |
Remove
Description | Rule |
---|---|
Removes leading 1 | [1,99]->^1(.+)->$1 |
Removes leading +1 | [1,99]->^\+1(.+)->$1 |
Removes leading 41 | [1,99]->^41(.+)->$1 |
Removes leading +41 | [1,99]->^\+41(.+)->$1 |
Removes leading 49 | [1,99]->^49(.+)->$1 |
Removes leading +49 | [1,99]->^\+49(.+)->$1 |
Removes leading 91 | [1,99]->^91(.+)->$1 |
Removes leading +91 | [1,99]->^\+91(.+)->$1 |
Removes leading 91 or 9 | [1,99]->^(91|9)(.+)->$2 |
Removes all characters but digits | [1,99]->[^\d]+ |
Removes all characters but digits and + | [1,99]->[^+\d]+ |
Replace
Description | Rule |
---|---|
Replaces leading +1 with +91 | [1,99]->^\+1(.+)->+91$1 |
Replaces leading + with 00 | [1,99]->^\+(.+)->00$1 |
Replaces leading +49 with 0049 | [1,99]->^\+49(.+)->0049$1 |
Replaces leading +1 with 001 | [1,99]->^\+1(.+)->001$1 |
Specific Rules
Removes country codes
[1,99]->^\+(9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|4[987654310]|3[9643210]|2[70]|7|1)(.+)->$2
Removes leading +1 and adds a dash (-) after the 3rd an 6th digit
[1,99]->^\+1(\d{3})(\d{3})(\d+)->$1-$2-$3