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 throw an App Error.

{
  "airkitErrorType": "ApplicationError",
  "sourceProject": "cxr-undefined",
  "name": "ApplicationError",
  "identifier": "error.application.airscript.function.parse-phone",
  "metadata": {
    "message": "invalid-country-code",
    "url": "https://us.api.prod.airkit.com/internal/session-gateway/v1/connection/run",
    "statusText": "",
    "statusCode": 400
  },
  "httpStatus": 400
}

Declaration

PARSE_PHONE(phone_number_string, region) -> phone 

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") -> ERROR

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") -> ERROR

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

Country CodeCountry NamePhone Prefix
AFAfghanistan+93
ALAlbania+355
DZAlgeria+213
ASAmerican Samoa+1684
ADAndorra+376
AOAngola+244
AIAnguilla+1264
AQAntarctica+672
AGAntigua and Barbuda+1268
ARArgentina+54
AMArmenia+374
AWAruba+297
AUAustralia+61
ATAustria+43
AZAzerbaijan+994
BSBahamas+1242
BHBahrain+973
BDBangladesh+880
BBBarbados+1246
BYBelarus+375
BEBelgium+32
BZBelize+501
BJBenin+229
BMBermuda+1441
BTBhutan+975
BOBolivia+591
BABosnia and Herzegovina+387
BWBotswana+267
BRBrazil+55
IOBritish Indian Ocean Territory+246
VGBritish Virgin Islands+1284
BNBrunei+673
BGBulgaria+359
BFBurkina Faso+226
MMMyanmar+95
BIBurundi+257
KHCambodia+855
CMCameroon+237
CACanada+1
CVCape Verde+238
KYCayman Islands+1345
CFCentral African Republic+236
TDChad+235
CLChile+56
CNChina+86
CXChristmas Island+61
CCCocos Islands+61
COColombia+57
KMComoros+269
CGRepublic of the Congo+242
CDDemocratic Republic of the Congo+243
CKCook Islands+682
CRCosta Rica+506
HRCroatia+385
CUCuba+53
CWCuracao+599
CYCyprus+357
CZCzech Republic+420
DKDenmark+45
DJDjibouti+253
DMDominica+1767
DODominican Republic+1809
DODominican Republic+1829
DODominican Republic+1849
TLEast Timor+670
ECEcuador+593
EGEgypt+20
SVEl Salvador+503
GQEquatorial Guinea+240
EREritrea+291
EEEstonia+372
ETEthiopia+251
FKFalkland Islands+500
FOFaroe Islands+298
FJFiji+679
FIFinland+358
FRFrance+33
PFFrench Polynesia+689
GAGabon+241
GMGambia+220
GEGeorgia+995
DEGermany+49
GHGhana+233
GIGibraltar+350
GRGreece+30
GLGreenland+299
GDGrenada+1473
GUGuam+1671
GTGuatemala+502
GGGuernsey+441481
GNGuinea+224
GWGuinea-Bissau+245
GYGuyana+592
HTHaiti+509
HNHonduras+504
HKHong Kong+852
HUHungary+36
ISIceland+354
INIndia+91
IDIndonesia+62
IRIran+98
IQIraq+964
IEIreland+353
IMIsle of Man+441624
ILIsrael+972
ITItaly+39
CIIvory Coast+225
JMJamaica+1876
JPJapan+81
JEJersey+441534
JOJordan+962
KZKazakhstan+7
KEKenya+254
KIKiribati+686
XKKosovo+383
KWKuwait+965
KGKyrgyzstan+996
LALaos+856
LVLatvia+371
LBLebanon+961
LSLesotho+266
LRLiberia+231
LYLibya+218
LILiechtenstein+423
LTLithuania+370
LULuxembourg+352
MOMacau+853
MKMacedonia+389
MGMadagascar+261
MWMalawi+265
MYMalaysia+60
MVMaldives+960
MLMali+223
MTMalta+356
MHMarshall Islands+692
MRMauritania+222
MUMauritius+230
YTMayotte+262
MXMexico+52
FMMicronesia+691
MDMoldova+373
MCMonaco+377
MNMongolia+976
MEMontenegro+382
MSMontserrat+1664
MAMorocco+212
MZMozambique+258
NANamibia+264
NRNauru+674
NPNepal+977
NLNetherlands+31
ANNetherlands Antilles+599
NCNew Caledonia+687
NZNew Zealand+64
NINicaragua+505
NENiger+227
NGNigeria+234
NUNiue+683
MPNorthern Mariana Islands+1670
KPNorth Korea+850
NONorway+47
OMOman+968
PKPakistan+92
PWPalau+680
PSPalestine+970
PAPanama+507
PGPapua New Guinea+675
PYParaguay+595
PEPeru+51
PHPhilippines+63
PNPitcairn+64
PLPoland+48
PTPortugal+351
PRPuerto Rico+1787
PRPuerto Rico+1939
QAQatar+974
REReunion+262
RORomania+40
RURussia+7
RWRwanda+250
BLSaint Barthelemy+590
WSSamoa+685
SMSan Marino+378
STSao Tome and Principe+239
SASaudi Arabia+966
SNSenegal+221
RSSerbia+381
SCSeychelles+248
SLSierra Leone+232
SGSingapore+65
SXSint Maarten+1721
SKSlovakia+421
SISlovenia+386
SBSolomon Islands+677
SOSomalia+252
ZASouth Africa+27
KRSouth Korea+82
SSSouth Sudan+211
ESSpain+34
LKSri Lanka+94
SHSaint Helena+290
KNSaint Kitts and Nevis+1869
LCSaint Lucia+1758
MFSaint Martin+590
PMSaint Pierre and Miquelon+508
VCSaint Vincent and the Grenadines+1784
SDSudan+249
SRSuriname+597
SJSvalbard and Jan Mayen+47
SZSwaziland+268
SESweden+46
CHSwitzerland+41
SYSyria+963
TWTaiwan+886
TJTajikistan+992
TZTanzania+255
THThailand+66
TGTogo+228
TKTokelau+690
TOTonga+676
TTTrinidad and Tobago+1868
TNTunisia+216
TRTurkey+90
TMTurkmenistan+993
TCTurks and Caicos Islands+1649
TVTuvalu+688
AEUnited Arab Emirates+971
UGUganda+256
GBUnited Kingdom+44
UAUkraine+380
UYUruguay+598
USUnited States+1
UZUzbekistan+998
VUVanuatu+678
VAVatican+379
VEVenezuela+58
VNVietnam+84
VIU.S. Virgin Islands+1340
WFWallis and Futuna+681
EHWestern Sahara+212
YEYemen+967
ZMZambia+260
ZWZimbabwe+263