A Visa-shaped value can survive form validation and still arrive at your API with different digits. This guide follows that failure through input normalization, JSON transport and persistence. Its examples use the same local profile as the card validator, so a displayed result can be reproduced.

Prefix, length and checksum are separate checks

Our configured Visa profile uses prefix 4 and lengths 13, 16 and 19. The Visa generator produces 16-digit fixtures; validator coverage is deliberately broader. The network length comparison documents that distinction for every configured network.

A matching prefix is a format candidate, not proof of an issued Visa account. A supported length is not a checksum pass. Even all three passing does not determine balance, ownership, funding type or payment acceptance.

The following cases are read directly from the downloadable fixture file. The JSON result separates input status, brand candidate, length and checksum:

CaseInput / conditionExpected result
visa-13'4222222222222'{"brand":"visa","checksum":"pass","length":"supported","status":"ok"}
visa-16'4111 1111-1111 1111'{"brand":"visa","checksum":"pass","length":"supported","status":"ok"}
visa-19'4532015112830366187'{"brand":"visa","checksum":"pass","length":"supported","status":"ok"}
visa-letter'4111x111111111111'{"brand":null,"checksum":"not-checked","length":"unresolved","status":"characters"}
visa-number4111111111111111{"brand":null,"checksum":"not-checked","length":"unresolved","status":"type"}

The letter in 4111x111111111111 is intentional. A helper that starts with String(value).replace(/\D/g, '') would conceal that error. This is the normalization function used by the tools and these tests:

export function normalizeInput(input) {
  if (typeof input !== 'string') return { status: 'type', digits: '' };
  // Accept only ASCII digits, ordinary/NBSP spaces and ASCII hyphens.
  if (/[^0-9 \u00a0-]/u.test(input)) return { status: 'characters', digits: '' };
  const digits = input.replace(/[ \u00a0-]/g, '');
  return { status: digits ? 'ok' : 'empty', digits };
}

A user can paste ordinary separators without being allowed to paste arbitrary characters. Preserve the raw field long enough to explain an error; do not truncate it to 16 digits before checking it.

Reproduce the transport bug

Download the complete guide test project , extract the files together, and use Node.js 22 or later:

node --test guide-examples.test.mjs
node guide-demo.mjs visa

No package installation or payment credentials are required. The first command includes this regression test:

test('Visa identifiers survive JSON as strings, but Number can lose digits', () => {
  const pan = '4532015112830366187';
  assert.equal(JSON.parse(JSON.stringify({ pan })).pan, pan);
  assert.equal(Number.isSafeInteger(Number(pan)), false);
  assert.notEqual(String(Number(pan)), pan);
  // This 19-digit value DOES fit signed 64-bit; not every such value overflows.
  assert.ok(BigInt(pan) <= (2n ** 63n) - 1n);
  assert.equal(inspectCard(Number(pan), profile).status, 'type');
});

4532015112830366187 is a passing 19-digit fixture. It fits a signed 64-bit integer, but JavaScript’s Number cannot represent it exactly. Converting the rounded result back to a string cannot recover the original digits. BigInt in the test demonstrates the distinction; it is not a recommendation to store PANs numerically.

Trace the field through each boundary

BoundaryUseful assertionFailure to catch
Form to applicationValue remains a string; malformed paste is reportedAutomatic removal of letters
Application to JSONDecoded string equals the original byte for byteNumeric JSON property loses precision
Import or spreadsheetColumn is explicitly imported as textType inference and scientific notation
Application to persistenceIdentifier type and length are checked before writingA 16-character schema rejects or truncates longer input
Persistence to displayRead-back fixture equals the original before maskingA display formatter hides data loss

Database behavior depends on the schema, database and configuration: a short column may reject an insert or truncate it. Test the actual adapter instead of promising one universal outcome. For production, avoid collecting or retaining PAN where your provider can supply a payment reference; string storage alone is not a security control.

What prefix 4 does not tell you

Historical Electron and V PAY lists are not a current product directory. In particular, a six-digit product prefix cannot be combined with the same fixed suffix length used after a four-digit prefix. This guide no longer offers that broken classifier. The prefix lookup explains its local scope, and the PAN structure guide separates prefix assumptions from issuer identification.

For a different parsing problem, the Mastercard range guide tests interval boundaries exhaustively. Neither that classifier nor this one replaces a provider’s accepted-card configuration. The Luhn explanation covers the checksum layer; the brand detection guide covers shared candidate selection.

Frequently Asked Questions

How many digits can this Visa profile validate?
The shared local profile accepts 13, 16 and 19 digits with prefix 4. The Visa generator currently emits 16 digits. These format rules do not establish that an account exists or that a gateway accepts it.
Can I identify Visa Electron or V PAY with this code?
No. The example identifies a local Visa prefix candidate. Product, funding and issuer classification need an appropriate maintained source; historical prefix lists are not a reliable replacement.
Do all 19-digit card numbers overflow a signed 64-bit integer?
No. Some fit and some do not. JavaScript Number has a smaller exact-integer range. Keep PANs as strings across the full data path instead of depending on either numeric limit.
Should validation remove every non-digit character?
No. This project accepts spaces, non-breaking spaces and ASCII hyphens, but rejects letters, newlines and non-ASCII digits. It also rejects numeric input rather than turning a potentially rounded number back into text.