Take US phone numbers in any number of formats and try to convert them to a standard format.

normal_phone(
  number,
  format = "(%a) %e-%l",
  na_bad = FALSE,
  convert = FALSE,
  rm_ext = FALSE
)

Arguments

number

A vector of phone number in any format.

format

The desired output format, with %a representing the 3-digit area code, %e representing the 3-digit exchange, and %l representing the 4-digit line number. The punctuation between each part of the format is used in the normalized number (e.g., "(%a) %e-%l" or "%a-%e-%l").

na_bad

logical; Should invalid numbers be replaced with NA.

convert

logical; Should keypad_convert() be invoked to replace numbers with their keypad equivalent.

rm_ext

logical; Should extensions be removed from the end of a number.

Value

A normalized telephone number.

Examples

normal_phone(number = c("916-225-5887"))
#> [1] "(916) 225-5887"