Luhn Algorithm Validator avatar

Luhn Algorithm Validator

Pricing

Pay per event

Go to Apify Store
Luhn Algorithm Validator

Luhn Algorithm Validator

Validate numbers using the Luhn checksum algorithm. Detects card brands (Visa, Mastercard, Amex, Discover, JCB, Diners Club, Maestro, UnionPay), IMEI, Canadian SINs, and other Luhn-validated IDs. Bulk validation with check digit correction.

Pricing

Pay per event

Rating

0.0

(0)

Developer

Stas Persiianenko

Stas Persiianenko

Maintained by Community

Actor stats

0

Bookmarked

2

Total users

1

Monthly active users

5 days ago

Last modified

Categories

Share

Validate numbers using the Luhn checksum algorithm (mod 10). Supports credit card numbers, IMEI numbers, Canadian Social Insurance Numbers (SINs), National Provider Identifiers (NPIs), and any other Luhn-validated ID format. Detects card brands (Visa, Mastercard, American Express, Discover, JCB, Diners Club, Maestro, UnionPay) automatically from prefix and length patterns.

What does Luhn Algorithm Validator do?

Luhn Algorithm Validator takes a list of numbers and validates each one against the Luhn checksum algorithm. For every number, it returns:

  • Validity status — whether the number passes the Luhn check
  • Check digit analysis — the actual check digit and the expected check digit (for invalid numbers)
  • Card brand detection — identifies Visa, Mastercard, Amex, Discover, JCB, Diners Club, Maestro, and UnionPay based on IIN (Issuer Identification Number) prefix ranges
  • Number type classification — detects payment cards, IMEI numbers, Canadian SINs, NPIs, and other Luhn-validated formats
  • Automatic normalization — strips spaces, dashes, dots, and parentheses before validation

The Luhn algorithm is used worldwide to validate identification numbers including credit card numbers (ISO/IEC 7812), IMEI numbers for mobile devices, Canadian Social Insurance Numbers, US National Provider Identifiers, and many government-issued IDs.

Who is Luhn Algorithm Validator for?

  • Fintech developers validating payment card numbers before processing transactions
  • Data quality engineers cleaning and validating large datasets of card or ID numbers
  • Fraud detection teams flagging numbers that fail Luhn checks as potentially fabricated
  • E-commerce platforms verifying card number formats before calling payment gateways
  • QA engineers generating and validating test card numbers for payment system testing
  • Compliance teams auditing PII datasets for valid card and ID number formats
  • Mobile device management teams validating IMEI numbers in bulk

Why use Luhn Algorithm Validator?

  • Zero cost per run — pure computation, no HTTP calls, no proxy, no browser. Runs in milliseconds
  • Bulk processing — validate thousands of numbers in a single run
  • Card brand detection — automatically identifies 8 major card networks from IIN prefix patterns
  • Detailed diagnostics — for invalid numbers, shows the expected check digit so you can correct them
  • Format-tolerant — handles numbers with spaces, dashes, dots, and parentheses
  • API-ready — integrate into any pipeline via Apify API, webhooks, or MCP

What data does Luhn Algorithm Validator return?

FieldTypeDescription
numberstringOriginal input as provided
numberNormalizedstringInput with spaces, dashes, dots removed
digitCountnumberNumber of digits after normalization
isValidbooleanWhether the number passes the Luhn check
checkDigitnumberActual last digit of the number
expectedCheckDigitnumberCorrect check digit (useful for fixing invalid numbers)
numberTypestringDetected type: Payment Card, IMEI, Canadian SIN, NPI, Other
cardBrandstringCard network: Visa, Mastercard, Amex, Discover, JCB, etc.
cardBrandCodestringShort code: VISA, MC, AMEX, DISC, JCB, DINERS, MAESTRO, UNIONPAY
iinRangestringIIN prefix range that matched (e.g., "4" for Visa, "51-55" for MC)
errorstringError message if input is malformed (non-digits, too short)

How much does it cost to validate numbers with Luhn algorithm?

Luhn Algorithm Validator uses pay-per-event pricing. You only pay for what you use.

EventFREE tierBRONZESILVERGOLDPLATINUMDIAMOND
Run started (one-time)$0.001$0.001$0.001$0.001$0.001$0.001
Per number validated$0.000345$0.0003$0.000234$0.00018$0.00012$0.000084

Example costs (BRONZE tier):

  • 10 numbers: $0.001 + $0.003 = $0.004
  • 100 numbers: $0.001 + $0.03 = $0.031
  • 1,000 numbers: $0.001 + $0.30 = $0.301
  • 10,000 numbers: $0.001 + $3.00 = $3.001

Free plan estimate: Apify's free tier gives you $5/month in platform credits. That's roughly 14,000 numbers per month at FREE tier pricing.

How to validate numbers with Luhn algorithm

  1. Go to Luhn Algorithm Validator on Apify Store
  2. Enter your numbers in the input field (one per line or as a JSON array)
  3. Click Start to run the validator
  4. View results in the Dataset tab — each number shows validity, check digit, and card brand
  5. Export results as JSON, CSV, or Excel, or connect via API

Input parameters

ParameterTypeRequiredDescription
numbersarrayYesList of numbers to validate. Spaces, dashes, and dots are stripped automatically.

Output example

{
"number": "4532015112830366",
"numberNormalized": "4532015112830366",
"digitCount": 16,
"isValid": true,
"checkDigit": 6,
"expectedCheckDigit": 6,
"numberType": "Payment Card",
"cardBrand": "Visa",
"cardBrandCode": "VISA",
"iinRange": "4",
"error": null
}

For invalid numbers, the output includes the expected check digit:

{
"number": "4532015112830367",
"numberNormalized": "4532015112830367",
"digitCount": 16,
"isValid": false,
"checkDigit": 7,
"expectedCheckDigit": 6,
"numberType": "Payment Card",
"cardBrand": "Visa",
"cardBrandCode": "VISA",
"iinRange": "4",
"error": null
}

Tips for best results

  • Strip formatting first — the validator handles spaces, dashes, and dots, but other characters (letters, symbols) will cause an error
  • Use check digit correction — when isValid is false, expectedCheckDigit tells you the correct last digit
  • Validate before payment calls — catching bad card numbers before hitting the payment gateway saves API fees and reduces declines
  • Test card numbers — use standard test numbers like 4111111111111111 (Visa), 5500000000000004 (Mastercard), 340000000000009 (Amex)
  • Batch for efficiency — send all numbers in a single run rather than one at a time, the start event is charged only once per run

Integrations

Luhn Algorithm Validator fits into data processing workflows:

  • Payment form validation — validate card numbers client-side before submitting to Stripe/PayPal/Braintree
  • ETL pipeline cleaning — validate a column of card/ID numbers in your data warehouse export, flag invalid rows
  • Fraud detection pipeline — integrate as a pre-filter: numbers failing Luhn checks are likely fabricated
  • QA test data generation — validate that your test card number generator produces Luhn-valid numbers
  • Apify webhook chains — trigger Luhn validation automatically when another actor outputs card-like data

API usage

Node.js

import { ApifyClient } from 'apify-client';
const client = new ApifyClient({ token: 'YOUR_API_TOKEN' });
const run = await client.actor('automation-lab/luhn-validator').call({
numbers: ['4111111111111111', '5500000000000004', '1234567890'],
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
console.log(items);

Python

from apify_client import ApifyClient
client = ApifyClient('YOUR_API_TOKEN')
run = client.actor('automation-lab/luhn-validator').call(run_input={
'numbers': ['4111111111111111', '5500000000000004', '1234567890'],
})
items = client.dataset(run['defaultDatasetId']).list_items().items
print(items)

cURL

curl "https://api.apify.com/v2/acts/automation-lab~luhn-validator/runs" \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-d '{"numbers": ["4111111111111111", "5500000000000004", "1234567890"]}'

MCP integration

Use Luhn Algorithm Validator directly from AI assistants via the Model Context Protocol (MCP).

Claude Code

$claude mcp add --transport http apify "https://mcp.apify.com?tools=automation-lab/luhn-validator"

Claude Desktop / Cursor / VS Code

Add to your MCP config file:

{
"mcpServers": {
"apify": {
"url": "https://mcp.apify.com?tools=automation-lab/luhn-validator"
}
}
}

Example prompts:

  • "Validate these credit card numbers: 4111111111111111, 5500000000000004"
  • "Check if 374245455400126 is a valid Amex number"
  • "Which of these numbers pass the Luhn check?"

Supported card brands

BrandPrefixLengthCode
Visa413, 16, 19VISA
Mastercard51-55, 2221-272016MC
American Express34, 3715AMEX
Discover6011, 644-649, 6516-19DISC
JCB3528-358916-19JCB
Diners Club300-305, 36, 3814, 16, 19DINERS
Maestro5018, 5020, 5038, 6304, 6759-676312-19MAESTRO
UnionPay6216-19UNIONPAY

Legality and compliance

The Luhn algorithm is a mathematical checksum formula — it does not access any external services, databases, or APIs. This actor performs pure computation on the numbers you provide. No data leaves the Apify platform. No external requests are made. The algorithm itself is public domain (US Patent 2,950,048, expired 1977).

Important: This tool validates number FORMAT only (checksum correctness). A Luhn-valid number is not necessarily an active, issued, or authorized card. Never use Luhn validation as a substitute for payment authorization.

FAQ

What is the Luhn algorithm? The Luhn algorithm (also called the modulus 10 or mod 10 algorithm) is a checksum formula used to validate identification numbers. It was created by IBM scientist Hans Peter Luhn in 1954. It detects single-digit errors and most transpositions of adjacent digits.

Can this validator check if a credit card is real? No. The Luhn algorithm only verifies mathematical correctness of the check digit. A Luhn-valid number may be expired, cancelled, or never issued. Use a payment gateway for authorization checks.

Why does my number show as invalid? Check these common causes: (1) the number has a typo in the last digit — compare checkDigit vs expectedCheckDigit, (2) the number contains letters or special characters that aren't stripped by normalization, (3) the number is too short (minimum 2 digits).

Does this work for non-card numbers like IMEI? Yes. The Luhn algorithm is the same regardless of number type. The validator also detects number types: IMEI (15 digits starting with 35), Canadian SIN (9 digits), NPI (10 digits), and payment cards (12-19 digits matching known IIN ranges).

How fast is the validation? Very fast — this is pure math with no HTTP requests. A batch of 10,000 numbers completes in under a second. Processing time is O(n) where n is the total number of digits across all input numbers.