Check if two vectors contain matching phone numbers. See Details section for
a full list of match types. is_match()
with default arguments is used to
implement ==
and !=
for phone vectors.
is_match()
accepts phone or atomic vectors. Atomic vectors are converted to
character for comparison. Note that although they can contain formatting
character vectors are not parsed with a default region, so they will only
ever be an "EXACT_MATCH"
if a country calling code is specified with +
at
the start. See Examples.
is_match(e1, e2, detailed = FALSE, strict = TRUE, not_number_na = TRUE)
A phone or character vector.
A phone or character vector.
If FALSE
, is_match()
returns a logical vector. If TRUE
,
it returns a character vector with the match type. See Details section for
possible return values.
If TRUE
, only "EXACT_MATCH"
is treated as a match. If
FALSE
, "EXACT_MATCH"
, "NSN_MATCH"
and "SHORT_NSN_MATCH"
are all
considered a match. Ignored if detailed = TRUE
.
If TRUE
, "NOT_A_NUMBER"
is converted to NA
.
A logical or character vector.
Possible return values for is_match(x, detailed = TRUE)
:
"EXACT_MATCH"
: The country_code, NSN, presence of a leading zero for
Italian numbers and any extension present are the same.
"NSN_MATCH"
: Either or both values has no region specified, and the NSNs
and extensions are the same.
"SHORT_NSN_MATCH"
: Either or both values has no region specified, or the
region specified is the same, and one NSN could be a shorter version of the
other number. This includes the case where one has an extension specified,
and the other does not.
"NOT_A_NUMBER"
: One of the input phone numbers failed to parse.
"NO_MATCH"
: All others.
For example, the numbers +1 345 657 1234
and 657 1234
are a
"SHORT_NSN_MATCH"
. The numbers +1 345 657 1234
and 345 657
are a
"NO_MATCH"
.
is_match()
: PhoneNumberUtil.isNumberMatch()
Other phone functions:
dialr-example
,
dialr-phone
,
dialr-region
,
dialr-type
,
dialr-valid
,
dialr
is_match(phone("0412 345 678", "AU"), phone("+61412345678", "AU"))
#> [1] TRUE
phone("0412 345 678", "AU") == phone("+61412345678", "AU")
#> [1] TRUE
phone("0412 345 678", "AU") != phone("+61412345678", "AU")
#> [1] FALSE
# character vectors are only fully specified with a country calling code
is_match("0412345678", "0412345678", detailed = TRUE)
#> [1] "NSN_MATCH"
is_match("+61412345678", "+61412345678", detailed = TRUE)
#> [1] "EXACT_MATCH"
is_match(phone("0412345678", "AU"), "0412345678", detailed = TRUE)
#> [1] "NSN_MATCH"
is_match(phone("+61412345678", "AU"), "+61412345678", detailed = TRUE)
#> [1] "EXACT_MATCH"