| Title: | Validation and Normalization of Financial Identifiers |
|---|---|
| Description: | Validate and normalize identifiers that are ubiquitous in financial technology data pipelines: payment card numbers (Luhn), International Bank Account Numbers (IBAN, ISO 13616), International Securities Identification Numbers (ISIN, ISO 6166), CUSIP, SEDOL, Legal Entity Identifiers (LEI, ISO 17442), Financial Instrument Global Identifiers (FIGI), SWIFT/BIC codes (ISO 9362) and Chinese Unified Social Credit Codes (GB 32100-2015). All checks run offline with base R only. |
| Authors: | Shengxin Hao [aut, cre] |
| Maintainer: | Shengxin Hao <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.1 |
| Built: | 2026-11-25 18:30:37 UTC |
| Source: | https://github.com/cran/finid |
A CUSIP is a nine character identifier for North American securities: eight
alphanumeric characters followed by a decimal check digit. cusip_valid()
verifies the structure and checksum; cusip_check_digit() computes the
check digit for an eight character prefix.
cusip_valid(x) cusip_check_digit(x)cusip_valid(x) cusip_check_digit(x)
x |
A character vector of CUSIPs (or eight character prefixes for
|
cusip_valid() returns a logical vector; cusip_check_digit()
returns an integer vector, NA for malformed input.
cusip_valid("037833100") # Apple Inc. cusip_valid("037833101") cusip_check_digit("03783310") cusip_valid("594918104") # Microsoft Corp.cusip_valid("037833100") # Apple Inc. cusip_valid("037833101") cusip_check_digit("03783310") cusip_valid("594918104") # Microsoft Corp.
A FIGI is a 12 character identifier defined by the Object Management Group.
The first two characters identify the certified provider, the third
character is always "G", characters 4 to 11 are upper-case consonants (or
digits) and character 12 is a check digit computed with the modulus 10
"double-add-double" technique.
figi_valid(x) figi_check_digit(x)figi_valid(x) figi_check_digit(x)
x |
A character vector of FIGIs (or 11 character prefixes for
|
figi_valid() returns a logical vector; figi_check_digit()
returns an integer vector, NA for malformed input.
figi_valid("BBG000BLNNH6") # International Business Machines Corp. figi_valid("BBG000BLNNH5") figi_check_digit("BBG000BLNNH")figi_valid("BBG000BLNNH6") # International Business Machines Corp. figi_valid("BBG000BLNNH5") figi_check_digit("BBG000BLNNH")
finid_detect() classifies each element of a character vector as one of
"lei", "uscc", "isin", "figi", "cusip", "sedol", "swift",
"iban", "pan" or "unknown" by running the corresponding validator.
finid_check() combines detection and validation into a data frame, which
is convenient for profiling an identifier column before loading it.
finid_detect(x) finid_check(x, type = NULL)finid_detect(x) finid_check(x, type = NULL)
x |
A character vector of identifiers. |
type |
Optional type to use for every element instead of detection.
One of |
When an identifier could satisfy more than one specification, types are tested in the order shown above.
finid_detect(): a character vector of types; NA for NA input and
"unknown" for values that match no supported type.
finid_check(): a data frame with the columns input, normalized,
type and valid.
finid_detect(c("US0378331005", "GB82WEST12345698765432", "not-an-id")) finid_check(c( "US0378331005", "GB82 WEST 1234 5698 7654 32", "037833100", "4532015112830366", NA )) finid_check("4532015112830366", type = "luhn")finid_detect(c("US0378331005", "GB82WEST12345698765432", "not-an-id")) finid_check(c( "US0378331005", "GB82 WEST 1234 5698 7654 32", "037833100", "4532015112830366", NA )) finid_check("4532015112830366", type = "luhn")
Removes whitespace and hyphens and converts input to upper case. Financial
identifiers are frequently copied from statements, invoices or web pages
with decorative separators; every validator in finid applies this
normalization before checking the identifier.
finid_normalize(x)finid_normalize(x)
x |
A character vector. Factors are converted to character; numeric and
logical input is converted with a warning-free |
A character vector of the same length as x, with NA values
preserved.
finid_normalize("gb82 west 1234 5698 7654 32") finid_normalize("4532-0151-1283-0366") finid_normalize(c(NA, "US0378331005"))finid_normalize("gb82 west 1234 5698 7654 32") finid_normalize("4532-0151-1283-0366") finid_normalize(c(NA, "US0378331005"))
iban_valid() validates IBANs against the ISO 13616 registry: country code,
total length, national (BBAN) structure and the modulus 97 check digits.
The remaining functions extract components and format a valid IBAN in
groups of four characters.
iban_valid(x) iban_format(x) iban_country(x) iban_check_digits(x) iban_bban(x)iban_valid(x) iban_format(x) iban_country(x) iban_check_digits(x) iban_bban(x)
x |
A character vector of IBANs. Spaces and hyphens are removed before
validation; see |
iban_valid(): a logical vector.
iban_country(), iban_check_digits(), iban_bban(): a character
vector, NA for invalid IBANs.
iban_format(): the IBAN in groups of four characters, NA for invalid
IBANs.
iban_valid("GB82WEST12345698765432") iban_valid("GB82WEST12345698765431") iban_format("GB82 WEST 1234 5698 7654 32") iban_country("DE89370400440532013000") iban_bban("DE89370400440532013000")iban_valid("GB82WEST12345698765432") iban_valid("GB82WEST12345698765431") iban_format("GB82 WEST 1234 5698 7654 32") iban_country("DE89370400440532013000") iban_bban("DE89370400440532013000")
isin_valid() checks the structure (ISO 3166 country prefix plus nine
alphanumeric characters and one decimal check digit) and the Luhn checksum
of an ISIN. The special prefix "XS" used for internationally cleared
securities is accepted in addition to ISO 3166-1 alpha-2 codes.
isin_valid(x) isin_check_digit(x) isin_country(x)isin_valid(x) isin_check_digit(x) isin_country(x)
x |
A character vector of ISINs. Spaces and hyphens are removed before
validation; see |
isin_valid(): a logical vector.
isin_country(): the two-character prefix, NA for invalid ISINs.
isin_check_digit(): the check digit for an 11 character ISIN prefix
(country code plus nine characters), NA if the prefix is malformed.
isin_valid("US0378331005") isin_valid("US0378331004") isin_country("US0378331005") isin_check_digit("US037833100") # Rebuild a valid ISIN from its prefix paste0("US037833100", isin_check_digit("US037833100"))isin_valid("US0378331005") isin_valid("US0378331004") isin_country("US0378331005") isin_check_digit("US037833100") # Rebuild a valid ISIN from its prefix paste0("US037833100", isin_check_digit("US037833100"))
An LEI is a 20 character identifier for legal entities that take part in
financial transactions (ISO 17442). Characters 1 to 4 identify the issuing
Local Operating Unit, characters 5 and 6 are reserved and must be "00",
characters 7 to 18 identify the entity and characters 19 to 20 hold the
modulus 97 check digits.
lei_valid(x) lei_check_digits(x)lei_valid(x) lei_check_digits(x)
x |
A character vector of LEIs (or 18 character prefixes for
|
lei_valid() returns a logical vector; lei_check_digits() returns
a two character vector, NA for malformed input.
lei_valid("529900T8BM49AURSDO55") lei_valid("529900T8BM49AURSDO54") lei_check_digits("529900T8BM49AURSDO")lei_valid("529900T8BM49AURSDO55") lei_valid("529900T8BM49AURSDO54") lei_check_digits("529900T8BM49AURSDO")
luhn_valid() checks whether a number satisfies the Luhn (modulus 10)
checksum that protects payment card numbers and several other identifiers.
pan_valid() additionally enforces the 12 to 19 digit length of a primary
account number (PAN). luhn_check_digit() computes the check digit that has
to be appended to an incomplete number.
luhn_valid(x) pan_valid(x) luhn_check_digit(x)luhn_valid(x) pan_valid(x) luhn_check_digit(x)
x |
A character vector of numbers. Non-digit characters (after normalization) make the corresponding element invalid. |
Input may contain spaces or hyphens; see finid_normalize().
luhn_valid() and pan_valid(): a logical vector. NA input yields
NA.
luhn_check_digit(): an integer vector with values 0 to 9, or NA when
the input cannot be completed.
luhn_valid("4532015112830366") luhn_valid("4532015112830367") pan_valid("4532 0151 1283 0366") # Check digit of a 15 digit body luhn_check_digit("453201511283036") # Round trip paste0("123456789", luhn_check_digit("123456789")) luhn_valid(paste0("123456789", luhn_check_digit("123456789")))luhn_valid("4532015112830366") luhn_valid("4532015112830367") pan_valid("4532 0151 1283 0366") # Check digit of a 15 digit body luhn_check_digit("453201511283036") # Round trip paste0("123456789", luhn_check_digit("123456789")) luhn_valid(paste0("123456789", luhn_check_digit("123456789")))
A SEDOL (Stock Exchange Daily Official List) number is a seven character identifier for securities listed on the London Stock Exchange: six alphanumeric characters followed by a decimal check digit. The six characters are weighted 1, 3, 1, 7, 3, 9 and the check digit makes the weighted sum a multiple of ten.
sedol_valid(x) sedol_check_digit(x)sedol_valid(x) sedol_check_digit(x)
x |
A character vector of SEDOLs (or six character prefixes for
|
sedol_valid() returns a logical vector; sedol_check_digit()
returns an integer vector, NA for malformed input.
sedol_valid("0263494") # BAE Systems plc sedol_valid("0263495") sedol_check_digit("026349") sedol_valid("B0YQ5W0")sedol_valid("0263494") # BAE Systems plc sedol_valid("0263495") sedol_check_digit("026349") sedol_valid("B0YQ5W0")
swift_valid() checks the structure of a Business Identifier Code
(ISO 9362): four letters for the institution, a two letter ISO 3166-1
country code, a two character location code and an optional three character
branch code.
swift_valid(x) swift_country(x) swift_bic8(x) swift_branch(x)swift_valid(x) swift_country(x) swift_bic8(x) swift_branch(x)
x |
A character vector of BIC codes. Spaces and hyphens are removed before validation. |
swift_valid(): a logical vector.
swift_country(): the country code, NA for invalid codes.
swift_bic8(): the eight character institution identifier, NA for
invalid codes.
swift_branch(): the three character branch code, NA for invalid codes
or codes without a branch suffix (an eight character BIC refers to the
primary office).
swift_valid("DEUTDEFF") swift_valid("DEUTDEFF500") swift_valid("DEUTDEFFXX") swift_country("DEUTDEFF500") swift_bic8("DEUTDEFF500") swift_branch("DEUTDEFF500")swift_valid("DEUTDEFF") swift_valid("DEUTDEFF500") swift_valid("DEUTDEFFXX") swift_country("DEUTDEFF500") swift_bic8("DEUTDEFF500") swift_branch("DEUTDEFF500")
The Unified Social Credit Code (USCC) is the 18 character
business identifier used in China (GB 32100-2015). The first 17 characters
come from a 31 character alphabet (digits and upper-case letters excluding
I, O, S, V and Z) and the last character is a check code weighted
by 1, 3, 9, 27, ... and taken modulo 31.
uscc_valid(x) uscc_check_digit(x)uscc_valid(x) uscc_check_digit(x)
x |
A character vector of USCCs (or 17 character prefixes for
|
uscc_valid() returns a logical vector; uscc_check_digit() returns
a one character vector, NA for malformed input.
uscc_valid("91350100M000100Y43") uscc_valid("91350100M000100Y44") uscc_check_digit("91350100M000100Y4")uscc_valid("91350100M000100Y43") uscc_valid("91350100M000100Y44") uscc_check_digit("91350100M000100Y4")