{"id":90,"date":"2026-06-09T14:16:26","date_gmt":"2026-06-09T06:16:26","guid":{"rendered":"https:\/\/formvalidation.io\/blog\/?p=90"},"modified":"2026-06-09T14:40:26","modified_gmt":"2026-06-09T06:40:26","slug":"luhn-algorithms-digit-checker-validator","status":"publish","type":"post","link":"https:\/\/formvalidation.io\/blog\/luhn-algorithms-digit-checker-validator\/","title":{"rendered":"Luhn Algorithm&#8217;s digit checker &amp; validator"},"content":{"rendered":"\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n<!-- Paste this entire block into a WordPress \"Custom HTML\" block -->\r\n<style>\r\n  #luhn-root, #luhn-root * { box-sizing: border-box; }\r\n  #luhn-root {\r\n    font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif;\r\n    background: #fff;\r\n    border-radius: 16px;\r\n    box-shadow: 0 10px 30px rgba(0,0,0,0.08);\r\n    padding: 32px;\r\n    width: 100%;\r\n    max-width: 560px;\r\n    margin: 24px auto;\r\n    color: #111827;\r\n    line-height: 1.4;\r\n  }\r\n  #luhn-root h2.luhn-title {\r\n    font-size: 22px;\r\n    margin: 0 0 4px;\r\n    color: #111827;\r\n    font-weight: 700;\r\n  }\r\n  #luhn-root p.luhn-subtitle {\r\n    margin: 0 0 24px;\r\n    color: #6b7280;\r\n    font-size: 14px;\r\n  }\r\n  #luhn-root label.luhn-label {\r\n    display: block;\r\n    font-size: 13px;\r\n    font-weight: 600;\r\n    color: #374151;\r\n    margin-bottom: 8px;\r\n  }\r\n  #luhn-root input.luhn-input {\r\n    width: 100%;\r\n    padding: 14px 16px;\r\n    font-size: 18px;\r\n    border: 2px solid #e5e7eb;\r\n    border-radius: 10px;\r\n    outline: none;\r\n    background: #fff;\r\n    color: #111827;\r\n    font-family: ui-monospace, \"SF Mono\", Menlo, monospace;\r\n    letter-spacing: 2px;\r\n    transition: border-color 0.15s, box-shadow 0.15s;\r\n    -webkit-appearance: none;\r\n    appearance: none;\r\n  }\r\n  #luhn-root input.luhn-input:focus {\r\n    border-color: #6366f1;\r\n    box-shadow: 0 0 0 4px rgba(99,102,241,0.15);\r\n  }\r\n  #luhn-root input.luhn-valid { border-color: #10b981; }\r\n  #luhn-root input.luhn-invalid { border-color: #ef4444; }\r\n  #luhn-root .luhn-status {\r\n    margin-top: 14px;\r\n    padding: 14px 16px;\r\n    border-radius: 10px;\r\n    font-size: 15px;\r\n    font-weight: 600;\r\n    display: flex;\r\n    align-items: center;\r\n    gap: 10px;\r\n  }\r\n  #luhn-root .luhn-status.luhn-state-valid { background: #ecfdf5; color: #047857; }\r\n  #luhn-root .luhn-status.luhn-state-invalid { background: #fef2f2; color: #b91c1c; }\r\n  #luhn-root .luhn-status.luhn-state-idle { background: #f9fafb; color: #6b7280; }\r\n  #luhn-root .luhn-icon-text {\r\n    font-size: 20px;\r\n    line-height: 1;\r\n    flex-shrink: 0;\r\n    display: inline-block;\r\n    width: 22px;\r\n    text-align: center;\r\n  }\r\n  #luhn-root .luhn-grid {\r\n    display: grid;\r\n    grid-template-columns: 1fr 1fr;\r\n    gap: 10px;\r\n    margin-top: 14px;\r\n  }\r\n  #luhn-root .luhn-stat {\r\n    background: #f9fafb;\r\n    border-radius: 10px;\r\n    padding: 12px 14px;\r\n  }\r\n  #luhn-root .luhn-stat-lbl {\r\n    font-size: 11px;\r\n    text-transform: uppercase;\r\n    letter-spacing: 0.05em;\r\n    color: #6b7280;\r\n  }\r\n  #luhn-root .luhn-stat-val {\r\n    font-size: 16px;\r\n    font-weight: 700;\r\n    color: #111827;\r\n    margin-top: 2px;\r\n    font-variant-numeric: tabular-nums;\r\n  }\r\n  #luhn-root .luhn-calc {\r\n    margin-top: 16px;\r\n    background: #eef2ff;\r\n    border: 1px solid #e0e7ff;\r\n    border-radius: 10px;\r\n    padding: 14px;\r\n    font-size: 13px;\r\n    color: #3730a3;\r\n    line-height: 1.6;\r\n  }\r\n  #luhn-root .luhn-calc b { color: #1e1b4b; }\r\n  #luhn-root .luhn-calc-row {\r\n    display: grid;\r\n    grid-template-columns: repeat(auto-fit, minmax(28px, 1fr));\r\n    gap: 4px;\r\n    font-family: ui-monospace, \"SF Mono\", Menlo, monospace;\r\n    margin-top: 6px;\r\n  }\r\n  #luhn-root .luhn-calc-cell {\r\n    text-align: center;\r\n    padding: 4px 0;\r\n    background: #fff;\r\n    border-radius: 4px;\r\n    font-size: 12px;\r\n  }\r\n  #luhn-root .luhn-calc-cell.luhn-doubled {\r\n    background: #c7d2fe;\r\n    color: #1e1b4b;\r\n    font-weight: 700;\r\n  }\r\n  #luhn-root .luhn-calc-sum {\r\n    margin-top: 10px;\r\n    padding-top: 10px;\r\n    border-top: 1px solid #c7d2fe;\r\n  }\r\n  #luhn-root .luhn-examples {\r\n    margin-top: 20px;\r\n    padding-top: 18px;\r\n    border-top: 1px solid #f3f4f6;\r\n  }\r\n  #luhn-root .luhn-examples-title {\r\n    font-size: 12px;\r\n    text-transform: uppercase;\r\n    letter-spacing: 0.05em;\r\n    color: #6b7280;\r\n    margin: 0 0 10px;\r\n    font-weight: 600;\r\n  }\r\n  #luhn-root .luhn-chip {\r\n    display: inline-block;\r\n    margin: 4px 6px 4px 0;\r\n    padding: 6px 10px;\r\n    background: #f3f4f6;\r\n    border: 1px solid #e5e7eb;\r\n    border-radius: 6px;\r\n    font-family: ui-monospace, monospace;\r\n    font-size: 12px;\r\n    cursor: pointer;\r\n    color: #374151;\r\n    user-select: none;\r\n  }\r\n  #luhn-root .luhn-chip:hover { background: #e5e7eb; }\r\n<\/style>\r\n\r\n<div id=\"luhn-root\">\r\n  <h2 class=\"luhn-title\">Luhn Algorithm Credit Card Validator<\/h2>\r\n  <p class=\"luhn-subtitle\">Check whether a credit card number is valid using the Luhn (mod 10) checksum and identify the issuing card network.<\/p>\r\n\r\n  <label class=\"luhn-label\" for=\"luhn-input\">Card number<\/label>\r\n  <input id=\"luhn-input\" class=\"luhn-input\" type=\"text\" inputmode=\"numeric\" placeholder=\"0000 0000 0000 0000\" autocomplete=\"off\" maxlength=\"23\">\r\n\r\n  <div id=\"luhn-status\" class=\"luhn-status luhn-state-idle\">\r\n    <span class=\"luhn-icon-text\"><\/span>\r\n    <span id=\"luhn-status-text\">Enter a card number to validate.<\/span>\r\n  <\/div>\r\n\r\n  <div id=\"luhn-details\">\r\n    <div class=\"luhn-grid\">\r\n      <div class=\"luhn-stat\">\r\n        <div class=\"luhn-stat-lbl\">Card network<\/div>\r\n        <div class=\"luhn-stat-val\" id=\"luhn-brand\">\u2014<\/div>\r\n      <\/div>\r\n      <div class=\"luhn-stat\">\r\n        <div class=\"luhn-stat-lbl\">Length<\/div>\r\n        <div class=\"luhn-stat-val\" id=\"luhn-length\">\u2014<\/div>\r\n      <\/div>\r\n    <\/div>\r\n\r\n    <div class=\"luhn-calc\" id=\"luhn-calc\">\r\n      <div><b>Luhn calculation<\/b> \u2014 doubled digits highlighted; if doubling produces a two-digit number, the digits are summed.<\/div>\r\n      <div class=\"luhn-calc-row\" id=\"luhn-calc-digits\"><\/div>\r\n      <div class=\"luhn-calc-row\" id=\"luhn-calc-values\"><\/div>\r\n      <div class=\"luhn-calc-sum\">Sum: <b id=\"luhn-calc-sum\">0<\/b> \u00b7 Sum mod 10 = <b id=\"luhn-calc-mod\">0<\/b> \u00b7 <span id=\"luhn-calc-conclusion\">\u2014<\/span><\/div>\r\n    <\/div>\r\n  <\/div>\r\n\r\n  <div class=\"luhn-examples\">\r\n    <p class=\"luhn-examples-title\">Try a test number<\/p>\r\n    <span class=\"luhn-chip\" data-val=\"4111111111111111\">Visa 4111\u2026<\/span>\r\n    <span class=\"luhn-chip\" data-val=\"5555555555554444\">Mastercard<\/span>\r\n    <span class=\"luhn-chip\" data-val=\"378282246310005\">Amex<\/span>\r\n    <span class=\"luhn-chip\" data-val=\"6011111111111117\">Discover<\/span>\r\n    <span class=\"luhn-chip\" data-val=\"3530111333300000\">JCB<\/span>\r\n    <span class=\"luhn-chip\" data-val=\"30569309025904\">Diners<\/span>\r\n    <span class=\"luhn-chip\" data-val=\"4111111111111112\">Invalid (Luhn fail)<\/span>\r\n  <\/div>\r\n<\/div>\r\n\r\n<script>\r\n(function () {\r\n  function init() {\r\n    var root = document.getElementById(\"luhn-root\");\r\n    if (!root) { return setTimeout(init, 100); }\r\n    var inputEl    = document.getElementById(\"luhn-input\");\r\n    var statusEl   = document.getElementById(\"luhn-status\");\r\n    var statusIcon = statusEl.querySelector(\".luhn-icon-text\");\r\n    var statusText = document.getElementById(\"luhn-status-text\");\r\n    var detailsEl  = document.getElementById(\"luhn-details\");\r\n    var brandEl    = document.getElementById(\"luhn-brand\");\r\n    var lengthEl   = document.getElementById(\"luhn-length\");\r\n    var calcDigits = document.getElementById(\"luhn-calc-digits\");\r\n    var calcValues = document.getElementById(\"luhn-calc-values\");\r\n    var calcSumEl  = document.getElementById(\"luhn-calc-sum\");\r\n    var calcModEl  = document.getElementById(\"luhn-calc-mod\");\r\n    var calcConcl  = document.getElementById(\"luhn-calc-conclusion\");\r\n\r\n    detailsEl.style.display = \"none\";\r\n\r\n    function detectBrand(num) {\r\n      var n = num, len = n.length;\r\n      if (\/^4\/.test(n) && (len === 13 || len === 16 || len === 19)) return \"Visa\";\r\n      if ((\/^5[1-5]\/.test(n) || \/^2(2[2-9][1-9]|[3-6]\\d{2}|7([01]\\d|20))\/.test(n)) && len === 16) return \"Mastercard\";\r\n      if (\/^3[47]\/.test(n) && len === 15) return \"American Express\";\r\n      if ((\/^6011\/.test(n) || \/^65\/.test(n) || \/^64[4-9]\/.test(n)) && (len === 16 || len === 19)) return \"Discover\";\r\n      if ((\/^30[0-5]\/.test(n) || \/^3[68]\/.test(n)) && (len === 14 || len === 16 || len === 19)) return \"Diners Club\";\r\n      if (\/^35(2[89]|[3-8]\\d)\/.test(n) && len >= 16 && len <= 19) return \"JCB\";\r\n      if (\/^62\/.test(n) && len >= 16 && len <= 19) return \"UnionPay\";\r\n      if (\/^9792\/.test(n) && len === 16) return \"Troy\";\r\n      if (\/^(5018|5020|5038|6304|6759|6761|6763)\/.test(n) && len >= 12 && len <= 19) return \"Maestro\";\r\n      return \"Unknown\";\r\n    }\r\n\r\n    function luhn(num) {\r\n      var digits = num.split(\"\").map(Number);\r\n      var values = [], doubled = [], sum = 0;\r\n      for (var i = digits.length - 1, pos = 0; i >= 0; i--, pos++) {\r\n        var d = digits[i], v = d, isDoubled = (pos % 2 === 1);\r\n        if (isDoubled) { v = d * 2; if (v > 9) v -= 9; }\r\n        values.unshift(v); doubled.unshift(isDoubled); sum += v;\r\n      }\r\n      return { sum: sum, valid: sum % 10 === 0, values: values, doubled: doubled };\r\n    }\r\n\r\n    function formatGroups(num, brand) {\r\n      if (brand === \"American Express\") {\r\n        return num.replace(\/^(\\d{0,4})(\\d{0,6})(\\d{0,5}).*\/, function (_, a, b, c) {\r\n          return [a, b, c].filter(Boolean).join(\" \");\r\n        });\r\n      }\r\n      return num.replace(\/(\\d{4})(?=\\d)\/g, \"$1 \");\r\n    }\r\n\r\n    function setStatus(state, message, iconChar) {\r\n      statusEl.className = \"luhn-status luhn-state-\" + state;\r\n      statusIcon.textContent = iconChar || \"\";\r\n      statusText.textContent = message;\r\n    }\r\n\r\n    function renderCalc(result, digits) {\r\n      while (calcDigits.firstChild) calcDigits.removeChild(calcDigits.firstChild);\r\n      while (calcValues.firstChild) calcValues.removeChild(calcValues.firstChild);\r\n      for (var i = 0; i < digits.length; i++) {\r\n        var dCell = document.createElement(\"div\");\r\n        dCell.className = \"luhn-calc-cell\" + (result.doubled[i] ? \" luhn-doubled\" : \"\");\r\n        dCell.textContent = digits[i];\r\n        calcDigits.appendChild(dCell);\r\n        var vCell = document.createElement(\"div\");\r\n        vCell.className = \"luhn-calc-cell\" + (result.doubled[i] ? \" luhn-doubled\" : \"\");\r\n        vCell.textContent = result.values[i];\r\n        calcValues.appendChild(vCell);\r\n      }\r\n      calcSumEl.textContent = result.sum;\r\n      calcModEl.textContent = result.sum % 10;\r\n      calcConcl.textContent = result.valid ? \"Divisible by 10 = valid\" : \"Not divisible by 10 = invalid\";\r\n    }\r\n\r\n    function recalc() {\r\n      var raw = inputEl.value.replace(\/\\D\/g, \"\");\r\n      var tentativeBrand = detectBrand(raw);\r\n      inputEl.value = formatGroups(raw, tentativeBrand);\r\n\r\n      if (raw.length === 0) {\r\n        inputEl.classList.remove(\"luhn-valid\", \"luhn-invalid\");\r\n        detailsEl.style.display = \"none\";\r\n        setStatus(\"idle\", \"Enter a card number to validate.\", \"\");\r\n        return;\r\n      }\r\n      if (raw.length < 12) {\r\n        inputEl.classList.remove(\"luhn-valid\", \"luhn-invalid\");\r\n        detailsEl.style.display = \"none\";\r\n        setStatus(\"idle\", \"Keep typing... (\" + raw.length + \" digits so far)\", \"\");\r\n        return;\r\n      }\r\n\r\n      var brand = detectBrand(raw);\r\n      var result = luhn(raw);\r\n      brandEl.textContent = brand;\r\n      lengthEl.textContent = raw.length + \" digits\";\r\n      renderCalc(result, raw.split(\"\"));\r\n      detailsEl.style.display = \"\";\r\n\r\n      if (result.valid) {\r\n        inputEl.classList.add(\"luhn-valid\");\r\n        inputEl.classList.remove(\"luhn-invalid\");\r\n        setStatus(\"valid\", \"Valid card number \u2014 passes Luhn check (\" + brand + \")\", \"\u2713\");\r\n      } else {\r\n        inputEl.classList.add(\"luhn-invalid\");\r\n        inputEl.classList.remove(\"luhn-valid\");\r\n        setStatus(\"invalid\", \"Invalid card number \u2014 fails Luhn check\", \"\u2717\");\r\n      }\r\n    }\r\n\r\n    inputEl.addEventListener(\"input\", recalc);\r\n    inputEl.addEventListener(\"keyup\", recalc);\r\n    inputEl.addEventListener(\"change\", recalc);\r\n    inputEl.addEventListener(\"paste\", function () { setTimeout(recalc, 10); });\r\n\r\n    var chips = root.querySelectorAll(\".luhn-chip\");\r\n    for (var i = 0; i < chips.length; i++) {\r\n      (function (chip) {\r\n        chip.addEventListener(\"click\", function () {\r\n          inputEl.value = chip.getAttribute(\"data-val\");\r\n          recalc();\r\n          inputEl.focus();\r\n        });\r\n      })(chips[i]);\r\n    }\r\n  }\r\n\r\n  if (document.readyState === \"loading\") {\r\n    document.addEventListener(\"DOMContentLoaded\", init);\r\n  } else {\r\n    init();\r\n  }\r\n})();\r\n<\/script>\n\n\n\n<h1 class=\"wp-block-heading\">Luhn Algorithm Credit Card Validator<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">A Luhn algorithm credit card validator is an online tool that verifies whether a payment card number is mathematically valid by applying the Luhn formula \u2014 the mod 10 checksum invented by IBM scientist Hans Peter Luhn in 1954 and still used today by every major card network. The validator above performs a complete credit card number check in your browser, identifies the issuing network, and shows the step-by-step Luhn calculation so you can see exactly why a given card number passes or fails.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is the Luhn algorithm?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The Luhn algorithm, also known as the mod 10 algorithm or the modulus 10 check, is a simple checksum formula that detects most accidental data-entry errors in identification numbers. It is the international standard ISO\/IEC 7812 and is applied to every credit card number, debit card number, and most other payment instruments in circulation. Because the Luhn algorithm is a mathematical check rather than a database lookup, a Luhn algorithm check confirms only that a number is well-formed \u2014 it does not confirm that the card was actually issued, that the account is open, or that funds are available.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How the Luhn algorithm works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The Luhn algorithm operates on the digits of a card number, working from right to left. Starting with the second-to-last digit, every other digit is doubled; if doubling produces a two-digit result, the two digits are added together (equivalent to subtracting nine). All resulting values, including the digits that were not doubled, are then summed. If the total is evenly divisible by ten, the card number is valid under the Luhn algorithm. The validator above reproduces this calculation in real time, with doubled positions highlighted so the logic is fully transparent.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to use this<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Type or paste a card number into the input field. The credit card validator automatically formats the digits into 4-4-4-4 groups (or 4-6-5 for American Express) as you type. Once at least twelve digits are present, the tool runs the Luhn check, identifies the card network from the BIN (the first six digits), and reports the result. A green badge indicates a valid card number that passes the Luhn check; a red badge indicates an invalid number. The card number check happens entirely in your browser \u2014 no card data is transmitted, logged, or stored on any server.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Supported card networks<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The credit card number checker detects and identifies every major global card network by BIN range and length: Visa (cards starting with 4), Mastercard (51\u201355 and the newer 2221\u20132720 range), American Express (34 and 37), Discover (6011, 644\u2013649, and 65), Diners Club (300\u2013305, 36, 38), JCB (3528\u20133589), UnionPay (62), Maestro, and Troy. If the BIN does not fall into a known range, the tool reports the network as Unknown but still completes the Luhn validation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common uses for a Luhn check<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Engineers integrating payment processors use a Luhn algorithm calculator to confirm test card numbers are well-formed before sending them to a sandbox gateway. Fraud and risk teams use the same check as the first line of defense against random or fat-finger card numbers in submitted orders. E-commerce developers embed Luhn validation client-side to catch typos before a transaction is submitted, reducing avoidable gateway declines and improving checkout conversion. Whatever the use case, a credit card validator built on the Luhn algorithm is the fastest and least invasive way to filter out obviously invalid numbers before any further processing occurs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Luhn Algorithm Credit Card Validator A Luhn algorithm credit card validator is an online tool that verifies whether a payment card number is mathematically valid by applying the Luhn formula \u2014 the mod 10 checksum invented by IBM scientist Hans Peter Luhn in 1954 and still used today by every major card network. The validator [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-90","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/formvalidation.io\/blog\/wp-json\/wp\/v2\/posts\/90","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/formvalidation.io\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/formvalidation.io\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/formvalidation.io\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/formvalidation.io\/blog\/wp-json\/wp\/v2\/comments?post=90"}],"version-history":[{"count":5,"href":"https:\/\/formvalidation.io\/blog\/wp-json\/wp\/v2\/posts\/90\/revisions"}],"predecessor-version":[{"id":98,"href":"https:\/\/formvalidation.io\/blog\/wp-json\/wp\/v2\/posts\/90\/revisions\/98"}],"wp:attachment":[{"href":"https:\/\/formvalidation.io\/blog\/wp-json\/wp\/v2\/media?parent=90"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/formvalidation.io\/blog\/wp-json\/wp\/v2\/categories?post=90"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/formvalidation.io\/blog\/wp-json\/wp\/v2\/tags?post=90"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}