{"record":{"id":"8b458c7231a09a09","repo":"validatorjs/validator.js","slug":"provider-is-not-a-valid-credit-card-provider","errorCode":null,"errorMessage":"${provider} is not a valid credit card provider.","messagePattern":"(.+?) is not a valid credit card provider\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/lib/isCreditCard.js","lineNumber":36,"sourceCode":"    if (cards.hasOwnProperty(cardProvider)) {\n      tmpCardsArray.push(cards[cardProvider]);\n    }\n  }\n  return tmpCardsArray;\n})();\n\nexport default function isCreditCard(card, options = {}) {\n  assertString(card);\n  const { provider } = options;\n  const sanitized = card.replace(/[- ]+/g, '');\n  if (provider && provider.toLowerCase() in cards) {\n    // specific provider in the list\n    if (!(cards[provider.toLowerCase()].test(sanitized))) {\n      return false;\n    }\n  } else if (provider && !(provider.toLowerCase() in cards)) {\n    /* specific provider not in the list */\n    throw new Error(`${provider} is not a valid credit card provider.`);\n  } else if (!allCards.some(cardProvider => cardProvider.test(sanitized))) {\n    // no specific provider\n    return false;\n  }\n  return isLuhnValid(card);\n}\n","sourceCodeStart":18,"sourceCodeEnd":43,"githubUrl":"https://github.com/validatorjs/validator.js/blob/a79ff980ab14257e795332989e497bdff3218e87/src/lib/isCreditCard.js#L18-L43","documentation":"isCreditCard(str, provider) optionally restricts validation to one card provider ('amex', 'dinersclub', 'discover', 'jcb', 'mastercard', 'unionpay', 'visa', 'mir', 'elo', 'hipercard'). Passing any other truthy provider string throws this error because the library cannot restrict to an unknown brand.","triggerScenarios":"isCreditCard('4111...', 'Visa Card') (name not an exact key), isCreditCard(num, 'MASTERCARD ')? with stray whitespace/typo like 'master card' or 'maestro', or a provider value read from user config.","commonSituations":"Free-form brand names from a database or API ('VISA credit') instead of the exact enum keys; assuming 'maestro' or 'rupay' are supported; case handled by the library but spelling must match the key exactly.","solutions":["Use one of the exact supported keys (lowercase, no spaces): amex, dinersclub, discover, jcb, mastercard, unionpay, visa, mir, elo, hipercard","Normalize/trim your provider string before calling","If the brand is not supported, call without a provider to validate against all cards","Check the current cards table in src/lib/isCreditCard.js for the supported set in your version"],"exampleFix":"// before\nvalidator.isCreditCard(num, 'Master Card'); // throws\n// after\nvalidator.isCreditCard(num, 'mastercard');","handlingStrategy":"validation","validationCode":"const CARDS = ['amex','dinersclub','discover','jcb','mastercard','unionpay','visa','mir','elo','hipercard'];\nconst providerOk = (p) => !p || CARDS.includes(String(p).toLowerCase().trim());\nif (!providerOk(provider)) throw new TypeError(`Unsupported provider: ${provider}`);","typeGuard":"const isCardProvider = (p) => typeof p === 'string' && CARDS.includes(p.toLowerCase().trim());","tryCatchPattern":"let ok;\ntry { ok = validator.isCreditCard(num, provider); }\ncatch (e) { if (/not a valid credit card provider/.test(e.message)) { ok = validator.isCreditCard(num); } else { throw e; } }","preventionTips":["Store provider names in your DB using the library's exact keys","Normalize with toLowerCase().trim() before calling","Call without a provider to validate against all cards when the brand is unknown","Re-check the supported card list when upgrading validator.js"],"tags":["validation","options","credit-card"],"backgroundTag":"invalid-provider-option","analyzedSha":"a79ff980ab14257e795332989e497bdff3218e87","analyzedAt":"2026-08-31T21:42:31.416Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}