Parses a phone number string into its components: country code, national
number, and region. Numbers can be provided in international format (with
leading +) or national format (with default_region).
Value
A list of parsed phone number lists, each with elements:
rawThe original input string.
country_codeCountry calling code (e.g.,
"64"for NZ).national_numberThe national significant number (digits only).
regionISO 3166-1 alpha-2 region code.
validLogical indicating if the number is valid.
Returns a list with valid = FALSE for numbers that cannot be parsed.
Examples
phone_parse("+64211234567")
#> [[1]]
#> [[1]]$raw
#> [1] "+64211234567"
#>
#> [[1]]$country_code
#> [1] "64"
#>
#> [[1]]$national_number
#> [1] "211234567"
#>
#> [[1]]$region
#> [1] "NZ"
#>
#> [[1]]$valid
#> [1] TRUE
#>
#>
phone_parse("021 123 4567", default_region = "NZ")
#> [[1]]
#> [[1]]$raw
#> [1] "021 123 4567"
#>
#> [[1]]$country_code
#> [1] "64"
#>
#> [[1]]$national_number
#> [1] "211234567"
#>
#> [[1]]$region
#> [1] "NZ"
#>
#> [[1]]$valid
#> [1] TRUE
#>
#>
phone_parse(c("+12125551234", "+442071234567"))
#> [[1]]
#> [[1]]$raw
#> [1] "+12125551234"
#>
#> [[1]]$country_code
#> [1] "1"
#>
#> [[1]]$national_number
#> [1] "2125551234"
#>
#> [[1]]$region
#> [1] "US"
#>
#> [[1]]$valid
#> [1] TRUE
#>
#>
#> [[2]]
#> [[2]]$raw
#> [1] "+442071234567"
#>
#> [[2]]$country_code
#> [1] "44"
#>
#> [[2]]$national_number
#> [1] "2071234567"
#>
#> [[2]]$region
#> [1] "GB"
#>
#> [[2]]$valid
#> [1] TRUE
#>
#>
