IT-LINUXMAKER, OpenSource, Tutorials

Dial patterns in FreePBX/Asterisk

Dial patterns are a central element in the configuration of FreePBX or Asterisk telephone systems. They are used to precisely define how dialed telephone numbers should be handled before they are forwarded via a trunk. They determine not only which numbers are allowed, but also how these numbers are adapted or rewritten—for example, by automatically adding a country code or removing a pre-dialed digit.

Think of dial patterns as a kind of "filter" or "set of rules" that examines each dialed number and then decides what can be done with it. For example, when a user dials a number, the system first checks whether that number matches a defined dial pattern. If so, the call is forwarded via the appropriate route or trunk. If not, the call is blocked or receives an error message.

What exactly are dial patterns used for?

The use of dial patterns is extremely versatile. In practice, they are often used to control which number ranges can be dialed – for example, national landline numbers, mobile numbers, emergency numbers, or international destinations. This can prevent employees from calling expensive premium numbers or from making unwanted international calls.

Another purpose is to transform or supplement phone numbers before they are sent outward. A typical example: A user dials a mobile number without a country code—for example, 01761234567. The system can automatically add the international dialing code +49 to this number, so that it arrives at the provider as +491761234567.

Dial patterns also make it possible to route different call destinations over different lines – for example, to save costs or use alternative providers. For example, all international calls could be routed over a cheaper SIP trunk, while domestic calls would be routed over the default provider.

In addition to control and convenience, dial patterns also contribute to security, as they allow you to specifically restrict access to certain phone numbers. Last but not least, they simplify users' everyday lives because they don't always have to dial full international formats—the system automatically fills in what's missing.

How are dial patterns structured

A dial pattern essentially consists of three to four components that together determine whether and how a dialed number should be processed. The most important part is the so-called match pattern – the actual number pattern that describes which number sequences are permitted. Wildcards can be used to respond flexibly to different number sequences. For example, an X represents any digit between 0 and 9, while a Z only allows the digits 1 to 9. Such wildcards can be used to represent, for example, all mobile phone numbers, all special numbers, or specific area codes.

Prefix and Prepend are two additional fields that determine how dialed digits are handled:

  • The Prefix is ​​a sequence of numbers that a user must actually dial—that is, a digit or a block of numbers that precedes the actual phone number. This is recognized by the system and removed before forwarding. For example, a user can first dial 0 to get an outside line—the system deletes this 0 and only sends the actual number out.
  • The Prepend field, on the other hand, is not selected by the user but is automatically prepended by the system as soon as the match pattern is met. It is used to add missing area codes or codes. A typical use case would be to automatically add a country and area code to internally dialed numbers so that they are valid externally.

Optionally, you can specify a CallerID field to apply dial patterns only to specific internal subscribers or groups. For example, you can configure it so that only certain extensions are allowed to make international calls.

Meaning of wildcards and fields in a dial pattern

In FreePBX and Asterisk, dial patterns are used to define which phone numbers are allowed and how they are processed. Wildcards are used to make patterns flexible. Here are the most important characters and fields, explained in simple terms:

Wildcards in the Match Pattern

  • X
    Represents any digit from 0 to 9.
    Example: 3XX allows all numbers from 300 to 399.
  • Z
    Applies to digits from 1 to 9 (i.e., not zero).
    Often used to exclude numbers that should not begin with 0.
    Example: ZXX matches 123, 987, but not 023.
  • N
    Allows digits from 2 to 9.
    Often used for area codes that cannot begin with 0 or 1.
    Example: NXX allows 200, 345, but not 012.
  • [ ] (Number set)
    In eckigen Klammern lassen sich mehrere Ziffern oder Bereiche zusammenfassen.
    Beispiel: [1237-9] steht für die Ziffern 1, 2, 3, 7, 8 und 9.
    Square brackets can be used to group multiple digits or ranges.
    Example: [1237-9] represents the digits 1, 2, 3, 7, 8, and 9.
  • . (Point)
    The dot means "any number of digits follow".
    Example: 0Z. allows all numbers that begin with a 0 followed by 1–9 and then contain further digits—for example, 0301234567.

The three central fields in a dial pattern

  • Match Pattern
    This is the pattern that the dialed number must match for the call to be accepted. It can contain the wildcards mentioned above.
    Example: A pattern of 01[5-7]X. allows all mobile numbers beginning with 015, 016, or 017.
  • Prefix
    Der Prefix ist ein fester Teil, den der Benutzer mitwählen muss, damit das Pattern greift.
    Wenn ein Anruf mit diesem Prefix beginnt, wird er vom System entfernt, bevor der Anruf weitergeleitet wird.
    Beispiel: Wählt ein Benutzer 901761234567, und der Prefix ist 9, dann wird die 9 entfernt – und die weitergeleitete Nummer ist 01761234567.
    The Prefix is ​​a fixed part that the user must dial for the pattern to work.
    If a call begins with this prefix, the system removes it before forwarding the call.
    For example, if a user dials 901761234567 and the prefix is ​​9, the 9 is removed, and the forwarded number is 01761234567.
  • Prepend
    The Prepend is a sequence of numbers that is automatically added to the dialed number after it has been successfully matched. The user does not see or select this part.
    For example, if +49 is set as the prepend and a user dials 1761234567, it becomes +491761234567.

How is a number processed?

When a number is dialed, the system compares it as follows:

Dialing number = Prefix + Match Pattern
Actual forwarded number = Prepend + (Match Pattern without prefix)

An example:

  • Prepend: +49
  • Prefix: 0
  • Match Pattern: 1[5-7]X.
  • The election is: 01761234567
    → The prefix 0 is removed, the pattern matches 1761234567,
    → Prepend +49 is prefixed
    → Forwarded: +491761234567

This mechanism makes dial patterns a very powerful tool. They ensure that calls only go to authorized and technically correct destinations—regardless of how the user originally enters the number.


IT-LINUXMAKER, OpenSource, IT-Support, IT-Consulting

© IT-LINUXMAKER 2025