FormatterHQ

Credit Card Number Validator (Luhn Check)

A developer tool for testing checkout forms: check card numbers against the Luhn checksum, detect the card network and verify the length. Nothing leaves your browser.

Input TEXT
Output TEXT
Ready.

How to use the Credit Card Validator

  1. Paste one or more card numbers, one per line; spaces and dashes are allowed.
  2. Optionally enable masking to hide the middle digits in the output.
  3. Read the result for each number: formatted number, detected network and whether it passes the length and Luhn checks.
  4. Use the results to verify your own form validation logic.

What this tool is for

If you build a checkout, subscription or donation form, you need to validate card numbers on the client before they ever reach your payment provider: catch typos early, show the right card logo and format the number as the user types. This credit card validator lets developers and QA testers check numbers against the same rules your form should apply, using the test card numbers that payment providers publish for exactly this purpose.

Important: a "valid" result only means the number is well-formed. It says nothing about whether a card exists, is active or has funds, and it cannot and does not contact any bank or card network. Only a payment processor can authorize a card.

Three checks in this credit card validator

  1. Network (IIN/BIN prefix) – the leading digits identify the network: Visa starts with 4, Mastercard with 51–55 or 2221–2720, American Express with 34 or 37, Discover with 6011, 644–649 or 65, and so on. Supported networks include Visa, Visa Electron, Mastercard, American Express, Discover, Diners Club, JCB, UnionPay, Maestro, RuPay and Mir.
  2. Length – each network allows specific lengths, such as 15 digits for Amex, 16 for Mastercard and 13, 16 or 19 for Visa.
  3. Luhn checksum – the last digit is a check digit that catches most single-digit typos and swapped neighboring digits.

How the Luhn algorithm works

Starting from the rightmost digit and moving left, double every second digit; if doubling gives a number above 9, subtract 9. Add all digits together. If the total is a multiple of 10, the number passes. For 4111 1111 1111 1111, the sum is 30, so it passes. Change any single digit and the sum is no longer a multiple of 10.

function luhn(digits) {
  let sum = 0, double = false;
  for (let i = digits.length - 1; i >= 0; i--) {
    let d = Number(digits[i]);
    if (double) { d *= 2; if (d > 9) d -= 9; }
    sum += d;
    double = !double;
  }
  return sum % 10 === 0;
}

Test numbers for development

Payment providers such as Stripe, Adyen, PayPal/Braintree and others publish test card numbers that pass these checks but only work in their sandbox environments, for example 4111 1111 1111 1111 (Visa), 5555 5555 5555 4444 (Mastercard) and 3782 822463 10005 (Amex). Use your provider's documented test numbers in development and never use real customer card data in test systems.

Example output:

Card number          Brand             Result
4111 1111 1111 1111  Visa              ✔ valid
3782 822463 10005    American Express  ✔ valid
4111 1111 1111 1112  Visa              ✘ invalid — fails the Luhn checksum

Masking

With masking enabled, only the first six and last four digits are shown (4111 11•• •••• 1111), matching the display rules commonly used under PCI DSS. Use it when you take screenshots for bug reports or documentation.

Privacy

All checks run in JavaScript in your browser; numbers are never transmitted or stored. Even so, do not paste real card numbers into any website you do not need to. For generating other kinds of test data, see the regex-based data generator, and for API experiments with a payment sandbox, the API tester.

Frequently asked questions

Does a valid result mean the card is real or has money on it?
No. The tool only checks the format: network prefix, length and Luhn checksum. It never contacts a bank, so it cannot tell whether a card exists or can be charged.
What is the Luhn algorithm?
It is a simple checksum formula, also called mod 10, used by card numbers and other identifiers. It detects most single-digit errors and swaps of adjacent digits.
Which test card numbers should I use?
Use the test numbers published by your payment provider, such as 4111 1111 1111 1111 for Visa. They pass validation but only work in the provider’s test mode.
Is it safe to paste card numbers here?
The check runs locally and nothing is sent or stored. Still, this is a developer tool, so use test numbers rather than real card data.
Why is a number flagged as unknown network?
Its leading digits do not match any supported network prefix. It may be a typo, a private-label or store card, or a network that the tool does not recognize.

Last updated October 3, 2026

Related tools

CSS Validator Validate CSS online: find unclosed braces, missing semicolons and other syntax errors. Email Address Validator Check email address syntax in bulk and flag typos in popular domains, disposable providers, role accounts and duplicates. HTML Validator Validate HTML markup online and find unclosed, mismatched or malformed tags. IBAN Validator Validate IBANs for 80+ countries with the MOD-97 checksum and country length rules, and see bank code and account parts. ISBN Validator & Converter Validate ISBN-10 and ISBN-13 check digits and convert between the two formats, one or many at a time. JavaScript Validator Check JavaScript for syntax errors online and find the exact line and column of each problem. Phone Number Validator & Formatter Validate phone numbers for 240+ regions and format them as E.164, international and national, with line type detection. TOML Validator Validate TOML files online against the TOML 1.0 spec. Find syntax errors by line and column and see the parsed data as JSON. UUID Validator & Decoder Validate UUIDs/GUIDs and decode version, variant and embedded timestamps for v1, v6 and v7 — many at once. API Tester (REST Client) Send GET, POST, PUT, PATCH and DELETE requests to REST APIs from your browser and inspect status, headers and pretty-printed JSON. Area Chart Maker Create area charts online from CSV or JSON data: filled line graphs with multiple series, smooth curves and SVG export. ASN.1 Decoder Parse DER/BER ASN.1 structures from PEM, Base64 or hex into a readable tree with OID names, strings, times and integers.