In addition to validity, libphonenumber can identify phone number type - it is able to distinguish Fixed-line, Mobile, Toll-free, Premium Rate, Shared Cost, VoIP, Personal Numbers, UAN, Pager, and Voicemail (whenever feasible).
get_type(x)
returns the phone number type for each element of a phone
vector.
Valid phone number types differ by region. get_types_for_region(x)
returns
a list of character vectors of valid types for each provided
ISO country code. Use get_supported_types()
to see a full
list of supported types.
get_type(x, strict = FALSE)
get_supported_types()
get_types_for_region(x)
A phone vector, or a character vector of ISO country codes.
If TRUE
, invalid phone numbers return NA
.
A character vector of phone types.
get_types_for_region()
returns a list of character vectors for each
provided country code.
get_type()
: PhoneNumberUtil.getNumberType()
get_supported_types()
: PhoneNumberUtil.PhoneNumberType
get_types_for_region()
: PhoneNumberUtil.getSupportedTypesForRegion()
Other phone functions:
dialr-example
,
dialr-match
,
dialr-phone
,
dialr-region
,
dialr-valid
,
dialr
# Get phone types for a phone vector
x <- phone(c(0, 0123, "0412 345 678", "61412987654", "03 9123 4567", "+12015550123"), "AU")
get_type(x)
#> [1] NA "UNKNOWN" "MOBILE"
#> [4] "MOBILE" "FIXED_LINE" "FIXED_LINE_OR_MOBILE"
# All supported phone types
get_supported_types()
#> [1] "FIXED_LINE" "MOBILE" "FIXED_LINE_OR_MOBILE"
#> [4] "TOLL_FREE" "PREMIUM_RATE" "SHARED_COST"
#> [7] "VOIP" "PERSONAL_NUMBER" "PAGER"
#> [10] "UAN" "VOICEMAIL" "UNKNOWN"
# Get supported types for specified regions
get_types_for_region("AU")
#> [[1]]
#> [1] "FIXED_LINE" "MOBILE" "TOLL_FREE" "PREMIUM_RATE" "SHARED_COST"
#> [6] "VOIP" "PAGER"
#>
get_types_for_region(c("GB", "US"))
#> [[1]]
#> [1] "FIXED_LINE" "MOBILE" "TOLL_FREE" "PREMIUM_RATE"
#> [5] "VOIP" "PERSONAL_NUMBER" "PAGER" "UAN"
#>
#> [[2]]
#> [1] "FIXED_LINE" "MOBILE" "TOLL_FREE" "PREMIUM_RATE"
#> [5] "PERSONAL_NUMBER"
#>
get_types_for_region(get_supported_regions())[1:5]
#> [[1]]
#> [1] "FIXED_LINE" "MOBILE" "TOLL_FREE" "PREMIUM_RATE"
#> [5] "PERSONAL_NUMBER"
#>
#> [[2]]
#> [1] "FIXED_LINE" "MOBILE" "TOLL_FREE" "SHARED_COST"
#>
#> [[3]]
#> [1] "FIXED_LINE" "MOBILE" "TOLL_FREE" "PREMIUM_RATE"
#> [5] "SHARED_COST" "VOIP" "PERSONAL_NUMBER" "UAN"
#> [9] "VOICEMAIL"
#>
#> [[4]]
#> [1] "FIXED_LINE" "MOBILE"
#>
#> [[5]]
#> [1] "FIXED_LINE" "MOBILE" "TOLL_FREE" "VOIP" "UAN"
#>