You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
isCreditCard returns true for the 4-digit string "5108" (and many other short or partial strings) due to a regex anchoring bug in the Mastercard pattern.
Reproduction (validator 13.15.35, the latest version on npm at time of writing)
After the fix, isCreditCard("5108") correctly returns false, and the valid 16-digit cases continue to return true.
Property that fails
// All credit-card-valid strings must have length within the documented per-issuer length ranges// (Mastercard: 16; including 19-digit private/extension forms it's still ≥ 13).functionprop(s){if(v.isCreditCard(s,{provider: "mastercard"})){returns.length>=13;// every passing input must be at least 13 chars}returntrue;}prop("5108");// false — invariant violated
Environment
validator: 13.15.35 (also reproduces in 13.12.0, so likely all 13.x)
Note for anyone landing on this: there are eight open PRs that all apply the same anchoring fix to the mastercard regex (#2739, #2741, #2788, #2794, #2799, #2854, #2942, #2976). They are the same change — wrapping the alternation so ^/$ apply to both branches — so one landing closes this issue and the other seven should be closed as duplicates.
I compared four of the variants against real inputs and they behave identically (16-digit 51/52/2221/2720 numbers match; 5100 and 5200 stop matching). The bug is still present on main today, and #2739 — the earliest — adds no regression test, so whichever is picked should bring a test that fails on today's main.
Activity
FullStraing commentedon Nov 20, 2026
Opened PR #2966 — anchors the Mastercard regex so short strings like '5108' and '51-08' are rejected, with regression tests.
FullStraing commentedon Nov 20, 2026
Opened a PR for this: #2966 — it anchors the Mastercard regex so short strings like '5108' are rejected, with regression tests.
tyza66 commentedon Nov 28, 2026
Note for anyone landing on this: there are eight open PRs that all apply the same anchoring fix to the
mastercardregex (#2739, #2741, #2788, #2794, #2799, #2854, #2942, #2976). They are the same change — wrapping the alternation so^/$apply to both branches — so one landing closes this issue and the other seven should be closed as duplicates.I compared four of the variants against real inputs and they behave identically (16-digit
51/52/2221/2720numbers match;5100and5200stop matching). The bug is still present onmaintoday, and#2739— the earliest — adds no regression test, so whichever is picked should bring a test that fails on today'smain.