Most Powerful Open Source ERP

Technical Note on Telephone Number Format

showing how to handle different format of telephone number by using regular expressions.
  • Last Update:2016-04-22
  • Version:001
  • Language:en

Telephone number format is different for each country or area, then we have to handle this issue using a regex regular expression.

Table of Contents

Draft

The point is how to get the correct regex to handle the telephone number input.

The Telephone (class) has a method called getRegexList that return the regex list.

Each regex will split the telephone input in country, area, number and extension.

The notation will be used by the asText method from Telephone (class) to print the country, area, number and extension following the notation configuration. The default notation is: +<country>(0)<area>-<number>/<ext>

How to add a regexp

The Telephone (class) has one list: regex_list.

The regex list have a regex for each input. Per example:

        +33(0)6-12345678/88

This possible input has a specific regex into the regex_list.

        "\+(?P<country>\d+)\(0\)(?P<area>\d+)\-(?P<number>[\d\ ]*)(?:\/)?(?P<ext>\d+|)"

Related Articles