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:
| Case | Input / condition | Expected 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-number | 4111111111111111 | {"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
| Boundary | Useful assertion | Failure to catch |
|---|---|---|
| Form to application | Value remains a string; malformed paste is reported | Automatic removal of letters |
| Application to JSON | Decoded string equals the original byte for byte | Numeric JSON property loses precision |
| Import or spreadsheet | Column is explicitly imported as text | Type inference and scientific notation |
| Application to persistence | Identifier type and length are checked before writing | A 16-character schema rejects or truncates longer input |
| Persistence to display | Read-back fixture equals the original before masking | A 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.