Test data only. Local fixtures do not issue cards, verify accounts or provide payment authorization. Use them only in authorized tests. Why?
5 test cards
- Generated fields are not uploaded
- Randomly generated in your browser
- Every number passes the Luhn check
Test JCB before the user finishes typing
Checking a full JCB fixture misses an input-state problem: the form may display an error at
35, leave that error visible after a correction, or stop accepting digits as soon as the
number reaches sixteen characters. This exercise follows the input through those states
instead of testing only the final value.
The generator above emits 16-digit, Luhn-valid numbers from the 3528–3589 prefix range,
with a three-digit synthetic security code. The separate JSON fixture extends the length
cases for a form configured to accept 16 through 19 digits.
Separate possible, complete and verified
Cybersource’s JCB identification reference
lists 3528–3589 and 16–19 digits. That is the explicit profile for the sample below;
it is not an exhaustive issuer database. Braintree’s
card-validator documentation
likewise distinguishes potentially valid input from a completed validation result.
Here, candidate means the typed prefix has reached four digits inside the configured
range. complete-shape means the prefix and length fit. Neither label means a checksum
was verified. One fixture deliberately has a wrong check digit while retaining the same
shape, so the distinction is visible in the tests.
| Input or action | Expected state | UI behavior to check |
|---|---|---|
| Empty input | empty | Clear stale brand and error state |
3, 35, then 352 | incomplete, candidate false | Allow more typing without claiming a completed JCB match |
3528 or 3589 | incomplete, candidate true | A provisional brand may appear; number remains unfinished |
3527 or 3590 | outside-profile | Explain that this prefix does not match the configured profile |
Backspace from 3590 to 35 | incomplete again | Remove the previous prefix error |
| Reach 16, 17 or 18 digits | complete-shape, can continue | Do not auto-submit or truncate the next digit |
| Reach 19, then 20 digits | Complete shape, then too-long | Retain the entered value and show the length error |
The card-length guide is a reference for choosing your application’s profile. Do not infer support from one fixture or enable every length without checking the processor integration you use.
Run the typing-state model
Download the JCB typing cases and the runnable input-state example together:
node --test jcb-typing.test.mjs
The runner checks the fixture states, every shorter prefix of the 19-digit example, and recovery after backspacing an out-of-profile prefix. This is the same model displayed here:
function jcbInputState(value) {
if (typeof value !== 'string') throw new TypeError('Use a string');
if (value === '') return { state: 'empty', candidate: false, canContinue: true };
if (!/^[0-9]+$/.test(value)) {
return { state: 'characters', candidate: false, canContinue: false };
}
const prefix = value.slice(0, 4);
const low = Number(prefix.padEnd(4, '0'));
const high = Number(prefix.padEnd(4, '9'));
if (high < 3528 || low > 3589) {
return { state: 'outside-profile', candidate: false, canContinue: false };
}
const candidate = value.length >= 4;
const state = value.length > 19 ? 'too-long'
: value.length >= 16 ? 'complete-shape' : 'incomplete';
return { state, candidate, canContinue: value.length < 19 };
}The function accepts an unformatted digit string. Spaces and letters return characters;
they are not silently removed. If your input component supports pasted separators, test
that normalization separately with the Visa input fixtures, then
feed its output into the state model. Keep the number as a string throughout.
Replay the sequence in your form
Replace jcbInputState in a copy of the runner with an adapter that returns the equivalent
states from your own component. Then type the sequence in a development checkout, including
backspace and replacement, without reloading the page between steps.
Observe whether the field error clears, whether focus stays in the input, and whether a sixteen-character mask prevents the seventeenth digit from reaching validation at all. A passing model test cannot detect that DOM-level truncation. For caret placement while editing a formatted number, use the Diners input-mask exercise.
Keep brand detection, checksum feedback and submission readiness as separate assertions. This sample never enables a payment button: a complete shape is just one input to that decision. Gateway behavior belongs in a second suite using your provider’s published fixtures from the sandbox reference.