跳转至

Parse phone number(解析电话号码)

Supported in: Batch, Streaming

Normalizes phone numbers to a common format, parsing them from various regions and formats. Phone numbers containing the + sign followed by the region code will be parsed correctly even if the region is not set. All other number formats require a region to be selected from the options provided in order for them to be correctly parsed. Phone numbers that cannot be parsed will result in nulls.

Expression categories: String

Declared arguments

  • Expression: Phone number to parse.
    Expression\
  • Format: Format to parse the phone number to.
    Enum\
  • optional Region: Region the phone number belongs to. Note: when region is not specified, parsing will be performed without it, which could lead to inaccurate or no result at all. This might be useful in case you have a variety of numbers and a single region cannot be assigned. Numbers containing country calling code will be parsed correctly even if the region is not set, but all other formats require a region to be selected.
    Enum\

Output type: Phone Number

Examples

Example 1: Base case

Description: Should return parsed number in the E164 with digits only format.

Argument values:

  • Expression: +1 415 5552671
  • Format: E164_DIGITS_ONLY
  • Region: US

Output: 14155552671


Example 2: Base case

Description: Should return parsed number in the E164 format.

Argument values:

  • Expression: +1 415 5552671
  • Format: E164
  • Region: US

Output: +14155552671


Example 3: Base case

Description: Should return parsed number in the INTERNATIONAL format.

Argument values:

  • Expression: +1 415 5552671
  • Format: INTERNATIONAL
  • Region: US

Output: +1 415-555-2671


Example 4: Base case

Description: Should return parsed number in the NATIONAL format.

Argument values:

  • Expression: +1 415 5552671
  • Format: NATIONAL
  • Region: US

Output: (415) 555-2671


Example 5: Base case

Description: Should return parsed number in the RFC3966 format.

Argument values:

  • Expression: +1 415 5552671
  • Format: RFC3966
  • Region: US

Output: tel:+1-415-555-2671


Example 6: Base case

Description: Return formatted US phone number

Argument values:

  • Expression: phoneNumber
  • Format: E164
  • Region: US
phoneNumber Output
(234) 235-5678 +12342355678
+1 415 5552671 +14155552671
(415) 5552671 +14155552671
Whatsapp@14155552671 +14155552671

Example 7: Null case

Description: If the phone number is un-parsable, the returned result is null

Argument values:

  • Expression: phoneNumber
  • Format: E164
  • Region: null
phoneNumber Output
null null
9991-COMPANY null
empty string null

Example 8: Edge case

Description: Phone numbers that contained the + sign and region code will be parsed to that specific region format even if the region is not set. Phone numbers that are missing the region coderequire a region to be selected from the dropdown in order for them to be correctly parsed. In this example the region code was not set, therefore numbers from the first, third, forth and fifth rows were not parsed correctly.

Argument values:

  • Expression: phoneNumber
  • Format: E164
  • Region: null
phoneNumber Output
(234) 235-5678 null
+1 415 5551111 +14155551111
1 415 555 1111 null
+1 411 1111111 null
+34 91 23 45678 +34912345678
Whatsapp@34912345678 null

Example 9: Edge case

Description: All phone numbers containing a country code were correctly parsed, as well as the phone numbers from the region selected have been parsed correctly. The phone numbers not matching the region selected were not parsed, as they were also invalid (too short or too long phone numbers).

Argument values:

  • Expression: phoneNumber
  • Format: E164
  • Region: US
phoneNumber Output
(234) 235-5678 +12342355678
+1 415 5551111 +14155551111
1 415 555 1111 +14155551111
+1 411 1111111 null
+447945120071 +447945120071
07945120071 null
not_a_phone_number null
Whatsapp@+34912345678 +34912345678


中文翻译


解析电话号码

支持:批处理(Batch)、流处理(Streaming)

将电话号码标准化为通用格式,支持解析来自不同地区和格式的号码。包含"+"号及地区代码的电话号码即使未设置地区也能正确解析。所有其他号码格式需要从提供的选项中选择地区才能正确解析。无法解析的电话号码将返回空值(null)。

表达式类别: 字符串(String)

声明的参数

  • 表达式(Expression): 待解析的电话号码。
    表达式\
  • 格式(Format): 电话号码的解析格式。
    枚举\
  • 可选 地区(Region): 电话号码所属地区。注意:未指定地区时,解析将在无地区信息的情况下进行,可能导致结果不准确或无法解析。当您拥有多种号码且无法指定单一地区时,此选项可能有用。包含国家呼叫代码的号码即使未设置地区也能正确解析,但所有其他格式需要选择地区。
    枚举\<阿富汗, 阿尔巴尼亚, 阿尔及利亚, 美属萨摩亚, 安道尔, 安哥拉, 安圭拉, 安提瓜和巴布达, 阿根廷, 亚美尼亚, 及其他...>

输出类型: 电话号码(Phone Number)

示例

示例1:基础情况

描述: 应返回仅含数字的E164格式解析结果。

参数值:

  • 表达式: +1 415 5552671
  • 格式: E164_DIGITS_ONLY
  • 地区: US

输出: 14155552671


示例2:基础情况

描述: 应返回E164格式的解析结果。

参数值:

  • 表达式: +1 415 5552671
  • 格式: E164
  • 地区: US

输出: +14155552671


示例3:基础情况

描述: 应返回国际格式(INTERNATIONAL)的解析结果。

参数值:

  • 表达式: +1 415 5552671
  • 格式: INTERNATIONAL
  • 地区: US

输出: +1 415-555-2671


示例4:基础情况

描述: 应返回国内格式(NATIONAL)的解析结果。

参数值:

  • 表达式: +1 415 5552671
  • 格式: NATIONAL
  • 地区: US

输出: (415) 555-2671


示例5:基础情况

描述: 应返回RFC3966格式的解析结果。

参数值:

  • 表达式: +1 415 5552671
  • 格式: RFC3966
  • 地区: US

输出: tel:+1-415-555-2671


示例6:基础情况

描述: 返回格式化后的美国电话号码

参数值:

  • 表达式: phoneNumber
  • 格式: E164
  • 地区: US
phoneNumber 输出
(234) 235-5678 +12342355678
+1 415 5552671 +14155552671
(415) 5552671 +14155552671
Whatsapp@14155552671 +14155552671

示例7:空值情况

描述: 如果电话号码无法解析,返回结果为null

参数值:

  • 表达式: phoneNumber
  • 格式: E164
  • 地区: null
phoneNumber 输出
null null
9991-COMPANY null
空字符串 null

示例8:边界情况

描述: 包含"+"号和地区代码的电话号码即使未设置地区也能解析为特定地区格式。缺少地区代码的电话号码需要从下拉菜单中选择地区才能正确解析。本示例中未设置地区代码,因此第一、三、四、五行中的号码未能正确解析。

参数值:

  • 表达式: phoneNumber
  • 格式: E164
  • 地区: null
phoneNumber 输出
(234) 235-5678 null
+1 415 5551111 +14155551111
1 415 555 1111 null
+1 411 1111111 null
+34 91 23 45678 +34912345678
Whatsapp@34912345678 null

示例9:边界情况

描述: 所有包含国家代码的电话号码均被正确解析,所选地区的电话号码也已正确解析。与所选地区不匹配的电话号码未能解析,因为它们也属于无效号码(号码过短或过长)。

参数值:

  • 表达式: phoneNumber
  • 格式: E164
  • 地区: US
phoneNumber 输出
(234) 235-5678 +12342355678
+1 415 5551111 +14155551111
1 415 555 1111 +14155551111
+1 411 1111111 null
+447945120071 +447945120071
07945120071 null
not_a_phone_number null
Whatsapp@+34912345678 +34912345678