Skip to main content
getBankNameFromCardNumber returns the Persian name of the bank that issued an Iranian card, by inspecting the leading 6-digit BIN.

Function

Return type — three states

Use === "string" rather than a truthy check.

Behaviour

  1. Falsy input → undefined.
  2. Stringified length must be in [6, 16]. Otherwise → null.
  3. Take the leading 6 characters as the BIN.
  4. Look up in the cardBank data table (src/modules/getBankNameFromCardNumber/banksCode.skip.ts).
  5. Return the Persian bank name or null.

Pitfalls

  • This is a lookup, not a validator. A nonsense tail (e.g. "603799 garbage") doesn’t matter as long as the BIN matches AND total length is in range. For checksum validation, use verifyCardNumber.
  • Persian/Arabic digit input is not normalized. Pre-convert with digitsFaToEn / autoConvertDigitsToEN if input may contain them.
  • The data table is curated; new banks may not appear until added.

Composition with verifyCardNumber

Source

src/modules/getBankNameFromCardNumber/index.ts · Tests: test/getBankNameFromCardNumber.spec.ts