Skip to contents

phone_parse() extracts the country calling code, national significant number, extension, region, validity, number type and E.164 representation for each element of a character vector.

Usage

phone_parse(x, region = NULL)

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.

Value

A data frame of class c("dialtone_phone", "data.frame") with one row per element of x and the columns:

  • country_code: integer country calling code (e.g. 1L, 44L, 91L), or NA_integer_.

  • national_number: character national significant number (preserving any significant leading zeros, as in Italian fixed-line numbers), or NA_character_.

  • extension: character extension digits if present, or NA_character_.

  • region: two-letter region code (or "001" for non-geographic numbers), or NA_character_.

  • possible: logical; TRUE if the length is possible for the calling code, FALSE otherwise, and NA where x is NA.

  • valid: logical; TRUE if the number matches a valid numbering-plan pattern, FALSE otherwise, and NA where x is NA.

  • type: character number type (see phone_type()), or NA_character_.

  • e164: character E.164 formatted number (+<country_code><national_number>), or NA_character_.

Examples

phone_parse(c("+1 650-253-0000", "020 7946 0192", "not a number", NA), region = "GB")
#>   country_code national_number extension region possible valid
#> 1            1      6502530000      <NA>     US     TRUE  TRUE
#> 2           44      2079460192      <NA>     GB     TRUE  TRUE
#> 3           NA            <NA>      <NA>   <NA>    FALSE FALSE
#> 4           NA            <NA>      <NA>   <NA>       NA    NA
#>                   type          e164
#> 1 fixed_line_or_mobile  +16502530000
#> 2           fixed_line +442079460192
#> 3                 <NA>          <NA>
#> 4                 <NA>          <NA>