Learn R Programming

assertive (version 0.2-6)

assert_all_are_us_telephone_numbers: Is the string a valid US telephone number?

Description

Checks that the input contains US/Canadian (NANPA) telephone numbers.

Usage

assert_all_are_us_telephone_numbers(x)

assert_any_are_us_telephone_numbers(x)

is_us_telephone_number(x)

Arguments

x
Input to check.

Value

  • is_us_telephone_number returns TRUE if the input string contains a valid US telephone number. The {assert_*} functions return nothing but throw an error when the is_* function returns FALSE.

Examples

Run this code
phone_numbers <- c(
  "12345678901",   #country code as 1
  "+12345678901",  #country code as +1
  "0012345678901", #country code as 001
  "2345678901",    #no country code
  "10345678901",   #NPA can't begin 0
  "11345678901",   #...or 1
  "12335678901",   #2nd, 3rd digits of NPA can't match
  "12340678901",   #NXX can't begin 0
  "12341678901",   #...or 1
  "12345118901",   #2nd, 3rd digits of NXX can't be 11
  "1234567",       #NPA must be included
  "12345678"      #ditto
)
is_us_telephone_number(phone_numbers)

Run the code above in your browser using DataLab