Financial data rarely arrives clean. Card numbers come from payment terminals, IBANs from customer onboarding forms, ISINs from market data vendors, LEIs from counterparty reference data, and SWIFT codes from settlement instructions. A single mistyped character can route a payment to the wrong account, reject a trade, or break a reconciliation.
finid performs the checksum and structure checks that can be done offline. Every validator is vectorized, accepts identifiers with spaces or hyphens, and returns NA for NA input, so the functions compose with dplyr, data.table or base R pipelines.
finid_normalize("gb82 west 1234 5698 7654 32")
#> [1] "GB82WEST12345698765432"
finid_normalize("4532-0151-1283-0366")
#> [1] "4532015112830366"
finid_normalize(c(NA, "us0378331005"))
#> [1] NA "US0378331005"pan_valid() checks the 12 to 19 digit length and the Luhn checksum. luhn_valid() applies the checksum to any length, which is useful for other Luhn-protected identifiers.
finid_check(c("4532015112830366", "4532015112830367"), type = "luhn")
#> input normalized type valid
#> 1 4532015112830366 4532015112830366 luhn TRUE
#> 2 4532015112830367 4532015112830367 luhn FALSE
luhn_check_digit("453201511283036")
#> [1] 6A Luhn checksum only shows that the digits are internally consistent. It does not show that an account exists or that the card is active; those checks require a payment processor.
iban_valid() verifies the country code, the registered total length, the national BBAN structure and the modulus 97 check digits. The registry table covers the countries listed by the ISO 13616 registry.
iban_valid(c(
"GB82WEST12345698765432",
"DE89370400440532013000",
"FR1420041010050500013M02606",
"GB82WEST12345698765431"
))
#> [1] TRUE TRUE TRUE FALSE
iban_format("GB82 WEST 1234 5698 7654 32")
#> [1] "GB82 WEST 1234 5698 7654 32"
iban_country("DE89370400440532013000")
#> [1] "DE"
iban_bban("DE89370400440532013000")
#> [1] "370400440532013000"ISINs combine a two letter ISO 3166 country prefix, a nine character national number and a Luhn check digit.
isin_valid(c("US0378331005", "GB0002634946", "US0378331004"))
#> [1] TRUE TRUE FALSE
isin_country("US0378331005")
#> [1] "US"
isin_check_digit("US037833100")
#> [1] 5CUSIPs identify North American securities and SEDOLs identify securities listed in London. Both validators also expose a *_check_digit() helper.
cusip_valid(c("037833100", "594918104", "17275R102"))
#> [1] TRUE TRUE TRUE
cusip_check_digit("17275R10")
#> [1] 2
sedol_valid(c("0263494", "B0YQ5W0", "0263498"))
#> [1] TRUE TRUE FALSE
sedol_check_digit("026349")
#> [1] 4lei_valid(c("529900T8BM49AURSDO55", "529900T8BM49AURSDO54"))
#> [1] TRUE FALSE
lei_check_digits("529900T8BM49AURSDO")
#> [1] "55"
figi_valid(c("BBG000BLNNH6", "BBG000BBDZG3", "BBG000BLNNH5"))
#> [1] TRUE TRUE FALSE
figi_check_digit("BBG000BLNNH")
#> [1] 6swift_valid(c("DEUTDEFF", "DEUTDEFF500", "DEUTZZFF"))
#> [1] TRUE TRUE FALSE
swift_country("DEUTDEFF500")
#> [1] "DE"
swift_bic8("DEUTDEFF500")
#> [1] "DEUTDEFF"
swift_branch("DEUTDEFF500")
#> [1] "500"finid_detect() infers the identifier type. finid_check() returns a data frame with the original value, the normalized value, the detected type and the validation result, which makes it easy to triage a column before loading it into a warehouse.
ids <- c(
"US0378331005",
"GB82 WEST 1234 5698 7654 32",
"037833100",
"4532015112830366",
"529900T8BM49AURSDO55",
"not-an-id",
NA
)
finid_detect(ids)
#> [1] "isin" "iban" "cusip" "pan" "lei" "unknown" NA
finid_check(ids)
#> input normalized type valid
#> 1 US0378331005 US0378331005 isin TRUE
#> 2 GB82 WEST 1234 5698 7654 32 GB82WEST12345698765432 iban TRUE
#> 3 037833100 037833100 cusip TRUE
#> 4 4532015112830366 4532015112830366 pan TRUE
#> 5 529900T8BM49AURSDO55 529900T8BM49AURSDO55 lei TRUE
#> 6 not-an-id NOTANID unknown FALSE
#> 7 <NA> <NA> <NA> NARows detected as "unknown" are structurally inconsistent with every supported specification. A row whose valid value is FALSE (for example a 12 character ISIN-like string with a bad check digit) matched a structure but failed its checksum.
finid never logs or stores values and only returns logical or character results.