PARSE_PHONE

** The PARSE_PHONE function takes a phone number string and returns the phone number in the E.164 general format.**

This function takes a string that represents a phone number and returns a properly formatted E.164 phone number string satisfying The Phone Variable Data Type requirements.

The region parameter is an optional two-digit country code that can be provided in case the phone string itself does not include a country code. If this parameter is omitted, the input phone number string must include the country code. If the input string contains a country code, the region parameter will be ignored.

If the input phone number string cannot be parsed into a valid phone number, the PARSE_PHONE function will return NULL.

Declaration

PARSE_PHONE(phone_number_string, region) -> phone | NULL

Parameters

phone_number_string (required, type: string) The string to parse the phone from.

region (optional, type: string) A two-character country code to be used phone_number_string

Return Values

phone (type: phone) The resulting E.164 formatted phone number, or NULL if phone_number_string does not represent a valid phone number.

Examples

Parsing a string that is already in E.164 format will produce the same string.

PARSE_PHONE("+17167762323") -> "+17167762323"

Additional characters in the input string will be stripped. In the following example all spaces, as well as the trailing "ext. 5" portion of the string, will be removed leaving just the E.164 formatted phone number.

PARSE_PHONE("+1-716-776-2323 ext. 5") -> "+17167762323"

When a phone number cannot be parsed, the PARSE_PHONE function will return NULL.

PARSE_PHONE("not a phone number") -> NULL

If a phone number has been collected from a user, it may not be in an E.164 format. The string "7167762323" is ambiguous without a country code as it may belong to more than one.

PARSE_PHONE("7167762323") -> NULL

However, when the country code is known, it can be provided as a hint.

PARSE_PHONE("7167762323", "US") -> "+17167762323"
PARSE_PHONE("(716) 776-2323", "US") -> "+17167762323"

Note, however, that this is just a hint. If the input phone number does include a country code, that country code will take precedence as in this example with an Australian phone number.

PARSE_PHONE("+61 (02) 5550 1234", "US") -> "+61255501234"
PARSE_PHONE("(02) 5550 1234", "AU") -> "+61255501234"

Supported Country Codes

Last updated