Technical Architecture: Payment Card Schemes & Prefix Detection Rules
In modern electronic commerce checkout experiences, frictionless checkout flows depend on instantaneous payment card brand detection. When a customer enters account numbers into a web or mobile checkout field, the user interface should immediately adapt: displaying the authentic brand emblem, enforcing the exact digit length, applying brand-specific grouping spaces (such as 4-6-5 for American Express or 4-4-4-4 for Visa and Mastercard), and toggling CVV helper hints between 3-digit reverse codes and 4-digit front codes.
This real-time responsiveness is powered by client-side regex pattern evaluation matching ISO/IEC 7812 specification guidelines. Because this processing happens locally in browser memory, checkout engines prevent unnecessary payment gateway API transactions for invalid inputs and eliminate card abandonment.
Comprehensive Comparison of Global Card Scheme Standards
Each global and domestic payment network maintains rigid structural specifications regarding Primary Account Number (PAN) prefixes, allowable length variations, and cryptographic verification values:
| Card Scheme | Prefix Rules (Regex Pattern) | Allowable PAN Lengths | Visual Spacing | Security Code Name & Length |
|---|---|---|---|---|
| Visa | ^4 | 13, 16, 19 digits | 4-4-4-4 (or 4-4-4-4-3) | CVV2 (3 digits, back) |
| Mastercard | ^(5[1-5]|2[2-7]) | 16 digits | 4-4-4-4 | CVC2 (3 digits, back) |
| American Express | ^3[47] | 15 digits | 4-6-5 | CID (4 digits, front) |
| Discover | ^(6011|65|64[4-9]|622) | 16, 19 digits | 4-4-4-4 (or 4-4-4-4-3) | CID (3 digits, back) |
| JCB | ^35(2[89]|[3-8][0-9]) | 16, 17, 18, 19 digits | 4-4-4-4 | CAV2 (3 digits, back) |
| China UnionPay | ^(62|81) | 16, 17, 18, 19 digits | 4-4-4-4 | CVN2 (3 digits, back) |
| RuPay | ^(508|60|6521|6522|81|82|3538) | 16 digits | 4-4-4-4 | CVD (3 digits, back) |
| Diners Club | ^(30[0-5]|36|38) | 14, 16 digits | 4-6-4 or 4-4-4-4 | CVV2 (3 digits, back) |
| Maestro | ^(50|5[6-9]|6) | 12 through 19 digits | Variable (4-4-4-4 standard) | CVC2 (3 digits, optional) |
| Mir | ^220[0-4] | 16 through 19 digits | 4-4-4-4 | MirAccept (3 digits, back) |
Deep-Dive into Major Card Brand Specifications
1. Visa (Prefix 4)
Visa is the world's most ubiquitous payment network. Under ISO 7812, all Visa card numbers begin with the single digit 4 (which designates Major Industry Identifier 4: Banking and Financial). While legacy Visa cards historically supported 13 digits, modern Visa cards universally feature 16 digits, with certain specialized contactless or transit cards supporting up to 19 digits. Visa card numbers are visually formatted in four equal blocks of 4 digits (4-4-4-4). The Card Verification Value 2 (CVV2) is a 3-digit code printed in reverse italics on the signature panel.
2. Mastercard (Prefixes 51-55 & 2221-2720)
Mastercard accounts historically began with prefixes in the 51 through 55 range. In 2017, Mastercard introduced the 2-Series BIN range spanning from 222100 to 272099. The 2-series behaves identically to 5-series cards in every transaction processing rule: standard 16-digit length, 4-4-4-4 grouping, and a 3-digit Card Validation Code 2 (CVC2) on the reverse side. Any merchant gateway that does not recognize 2-series prefixes risks erroneously declining legitimate Mastercard cardholders.
3. American Express (Prefixes 34 & 37)
American Express operates as a closed-loop and partner payment network. Amex Primary Account Numbers strictly begin with either 34 or 37 and contain exactly 15 digits. The numbers are spaced into three distinct blocks: four digits, six digits, and five digits (4-6-5). Additionally, American Express is the only major network that places its security code—the 4-digit Card Identification Number (CID)—on the front of the card, printed directly above the right-hand portion of the account number.
4. Discover & Discover Global Network
Discover cards begin with 6011, 65, the range 644-649, or the extended range 622126-622925 (co-assigned with China UnionPay). Standard Discover cards are 16 digits in length and use 4-4-4-4 spacing. The Discover security code is a 3-digit CID located on the back signature strip. Discover operates reciprocal merchant acceptance agreements with JCB, UnionPay, and Diners Club International under the Discover Global Network banner.
5. JCB (Prefixes 3528-3589)
JCB (formerly Japan Credit Bureau) cards begin with digits 3528 through 3589. JCB cards generally span 16 digits, though the specification allows 16 to 19 digits. Spacing follows the 4-4-4-4 format, and the security code is designated as Card Authentication Value 2 (CAV2), spanning 3 digits on the reverse.
6. RuPay (NPCI India)
Established by the National Payments Corporation of India to reduce dependency on foreign card schemes, RuPay cards use prefixes including 508, 60, 6521, and 6522, as well as 81 and 82. Most RuPay cards are 16 digits formatted in 4-4-4-4 grouping, utilizing a 3-digit Card Verification Digits (CVD) code. RuPay cards configured for international use feature a dual logo with Discover or JCB.
Client-Side Implementation: React / TypeScript Hook
Below is a clean, dependency-free React hook pattern for embedding real-time card brand detection into modern frontend forms:
// useCardBrand.ts - Lightweight Client-Side Card Scheme Detector
import { useMemo } from 'react';
export interface CardScheme {
brand: 'visa' | 'mastercard' | 'amex' | 'discover' | 'jcb' | 'unknown';
displayName: string;
cvvLength: number;
maxLength: number;
spacing: number[];
}
export function useCardBrand(pan: string): CardScheme {
return useMemo(() => {
const clean = pan.replace(/\D/g, '');
if (/^4/.test(clean)) {
return { brand: 'visa', displayName: 'Visa', cvvLength: 3, maxLength: 16, spacing: [4, 4, 4, 4] };
}
if (/^(5[1-5]|2[2-7])/.test(clean)) {
return { brand: 'mastercard', displayName: 'Mastercard', cvvLength: 3, maxLength: 16, spacing: [4, 4, 4, 4] };
}
if (/^3[47]/.test(clean)) {
return { brand: 'amex', displayName: 'American Express', cvvLength: 4, maxLength: 15, spacing: [4, 6, 5] };
}
if (/^(6011|65|64[4-9])/.test(clean)) {
return { brand: 'discover', displayName: 'Discover', cvvLength: 3, maxLength: 16, spacing: [4, 4, 4, 4] };
}
if (/^35(2[89]|[3-8][0-9])/.test(clean)) {
return { brand: 'jcb', displayName: 'JCB', cvvLength: 3, maxLength: 16, spacing: [4, 4, 4, 4] };
}
return { brand: 'unknown', displayName: 'Card', cvvLength: 3, maxLength: 19, spacing: [4, 4, 4, 4] };
}, [pan]);
} Luhn Modulo 10 Checksum Verification
In addition to prefix identification, valid payment card numbers must satisfy the Luhn algorithm (Modulo 10), defined in ISO/IEC 7812-1 Annex B. The algorithm verifies data integrity across manual keyboard entry:
- Starting from the rightmost check digit, moving leftward, double every second digit.
- If doubling results in a number greater than 9 (e.g., $7 \times 2 = 14$), sum the constituent digits ($1 + 4 = 5$) or subtract 9 ($14 - 9 = 5$).
- Sum all resulting values across the entire sequence.
- If the total modulo 10 equals zero (∑ mod 10 = 0), the card number is mathematically valid.
Security and Zero-Data Leakage Architecture
Because this tool executes 100% client-side inside the user's web browser, no account numbers, cardholder names, expiration dates, or CVV values are transmitted across external networks. Developers and QA engineers can test synthetic or masked PAN strings without violating PCI-DSS compliance mandates or exposing sensitive financial parameters to third-party analytic trackers.