is_credit_card_number: Does the character vector contain credit card numbers?

Description Usage Arguments Value Note References Examples

Description

Checks that the input contains credit card numbers.

Usage

1
2
3
4
5
6
7
8
assert_all_are_credit_card_numbers(x, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_any_are_credit_card_numbers(x, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

is_credit_card_number(x, type = c("visa", "mastercard", "amex", "diners",
  "discover", "jcb"))

Arguments

x

Input to check.

na_ignore

A logical value. If FALSE, NA values cause an error; otherwise they do not. Like na.rm in many stats package functions, except that the position of the failing values does not change.

severity

How severe should the consequences of the assertion be? Either "stop", "warning", "message", or "none".

type

Type of credit card. Multiple types can be selected.

Value

A logical vector that is TRUE when the input contains valid credit card numbers.

Note

Legacy card numbers, for example 13 digit Visa numbers and 15 digits JCB numbers are not supported.

References

http://www.regular-expressions.info/creditcard.html contains the regexes used by this function. The example valid card numbers were from PayPal developer documentation. The URL is no longer available.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
x <- c(
  #visa
  "4111 1111 1111 1111",    #spaces are allowed where they 
                            #would occur on the card
  "4012888888881881",       #though they can be omitted
  "4111 1111 1111 11111",   #too many digits
  "4012888888881882",       #bad check digit
  #mastercard
  "5555 5555 5555 4444",
  "5105 1051 0510 5100",
  "5655 5555 5555 4443",    #starts 56
  "51051 051 0510 5100",    #bad spacing
  #amex
  "3782 822463 10005",
  "3714 496353 98431",
  "3787 344936 71000", 
  "3782 822463 1005",       #not enough digits
  #diners
  "3056 930902 5904",
  "3852 000002 3237",
  #discover
  "6011 1111 1111 1117",
  "6011 0009 9013 9424",
  #jcb
  "3530 1113 3330 0000",
  "3566 0020 2036 0505"
)
is_credit_card_number(x)
assert_any_are_credit_card_numbers(x)
assertive.base::dont_stop(assert_all_are_credit_card_numbers(x))

assertive.data documentation built on May 2, 2019, 6:08 a.m.