Skip to contents

phone_format() formats parsed phone numbers according to Google's libphonenumber territory rules into "E164", "INTERNATIONAL", "NATIONAL" or "RFC3966" format.

Usage

phone_format(
  x,
  region = NULL,
  format = c("E164", "INTERNATIONAL", "NATIONAL", "RFC3966")
)

Arguments

x

A character vector of phone numbers (or an existing dialtone_phone data frame returned by phone_parse()).

region

A single two-letter CLDR region code (such as "US", "GB" or "IN") giving the default country for numbers written without a leading +, or NULL when numbers are in international format.

format

A single string naming the target format: "E164" (the default, e.g. "+41446681800"), "INTERNATIONAL" ("+41 44 668 1800"), "NATIONAL" ("044 668 1800"), or "RFC3966" ("tel:+41-44-668-1800"). Case-insensitive.

Value

A character vector the same length as x, with NA_character_ where x is NA or cannot be parsed.

Examples

x <- c("+41 44 668 1800", "+1 650-253-0000 ext. 1234", "not a number", NA)
phone_format(x, format = "E164")
#> [1] "+41446681800" "+16502530000" NA             NA            
phone_format(x, format = "INTERNATIONAL")
#> [1] "+41 44 668 18 00"          "+1 650-253-0000 ext. 1234"
#> [3] NA                          NA                         
phone_format(x, format = "NATIONAL")
#> [1] "044 668 18 00"            "(650) 253-0000 ext. 1234"
#> [3] NA                         NA                        
phone_format(x, format = "RFC3966")
#> [1] "tel:+41-44-668-18-00"         "tel:+1-650-253-0000;ext=1234"
#> [3] NA                             NA