Security-code fixtures

Generate three- or four-digit strings, including leading zeros. No card number is used to calculate these values.

    Use these values to test a security-code field, not to authenticate a card. The tool has no PAN input and no issuer connection. A fixed example is more useful than a random code when the bug depends on a leading zero or a change of required length.

    Leading-zero and network-switch cases

    Field valueRequired widthExpected format result
    "003"3Pass; retain all three characters through JSON and copy
    "0007"4Pass; do not convert to the number 7
    "003" after switching to a four-digit field4Fail; do not silently pad or accept the old value
    "0007" after switching to a three-digit field3Fail; do not silently cut the final digit
    "12x", "12 3" or "123\n"3Fail; unsupported characters remain visible to validation
    3 as a JSON number3Fail this string-based contract

    Select Try 000 / 003 / 999 or Try 0000 / 0007 / 9999 to load boundary fixtures immediately. Changing the length selector alone leaves existing results unchanged; Generate creates a new batch. JSON includes each code and its original length, so an edited selector cannot relabel an old result.

    The shared inspectSecurityCode function requires a string, an exact length of three or four and ASCII digits only. It checks length separately so a trailing newline cannot pass a permissive regular-expression end anchor. These are local form rules; use the test-card reference for your processor’s actual sandbox requirements.

    Export without losing width

    Copy returns one code per line. JSON preserves "code": "003"; CSV quotes the code column. A spreadsheet may still infer a number after parsing quoted CSV, so select Text for that column during import. Do not fix a broken import by adding zeros later: you would be hiding the stage that lost the original representation.

    A batch can contain repeated values. Random generation samples with replacement; there are only 1,000 possible three-digit strings and 10,000 four-digit strings. Deduplicating them is unnecessary for testing a field. Use the bulk generator when a code needs to travel with network, expiry and number fields.

    A logging example that does not copy the fixture

    Avoid passing an entire fixture object to a diagnostic event. This example selects only the four fields the event needs:

    export function fixtureLog(record) {
      // Allowlisted example event: adding fields to a fixture cannot add them to this log.
      return { event: 'fixture_checked', network: record.network, luhnValid: record.luhnValid, expired: record.expired };
    }

    The test passes extra cvv, cvc, cardNumber and nested contact fields, then asserts the exact output keys. This protects this particular function from future fixture fields being copied automatically. It does not inspect your application’s request logs, analytics SDK, screenshots, database or error reporter; those need their own checks.

    For production handling requirements, consult the PCI DSS guide. For the distinction between random test strings and issuer security codes, see why a CVV cannot be derived here.

    Run the field tests

    Download the security-code cases and test project , extract it and run node --test data-tools.test.mjs with Node.js 22 or later. The suite includes fixed leading-zero examples, wrong widths, numeric JSON input, letters, separators, trailing newlines and CSV preservation. The payment-form checklist places these checks alongside expiry, card number and address checks.

    Updated 8 November 2026: fixed boundary examples and original-length metadata were added; the earlier claim that every batch must contain duplicates was corrected.

    Frequently Asked Questions

    Can this calculate the security code for a card?
    No. No card number is an input. It generates independent random test strings and cannot retrieve or verify an issuer-issued security code.
    Why should I keep 003 as a string?
    Converting it to a number produces 3 and destroys the required width. JSON exports quoted strings; spreadsheet imports also need text columns.
    Will all generated codes be unique?
    No. There are only 1,000 possible three-digit strings and 10,000 four-digit strings. Repeats are possible even in small batches, but not inevitable in every batch.
    Does the logging example prove my application never logs codes?
    No. It only demonstrates a small event built from allowed fields. Inspect your request logger, analytics, error reporting and persistence separately.