validatorjs/validator.js · error · Error

${provider} is not a valid credit card provider.

Error message

${provider} is not a valid credit card provider.

What it means

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.

Source

Thrown at src/lib/isCreditCard.js:36

    if (cards.hasOwnProperty(cardProvider)) {
      tmpCardsArray.push(cards[cardProvider]);
    }
  }
  return tmpCardsArray;
})();

export default function isCreditCard(card, options = {}) {
  assertString(card);
  const { provider } = options;
  const sanitized = card.replace(/[- ]+/g, '');
  if (provider && provider.toLowerCase() in cards) {
    // specific provider in the list
    if (!(cards[provider.toLowerCase()].test(sanitized))) {
      return false;
    }
  } else if (provider && !(provider.toLowerCase() in cards)) {
    /* specific provider not in the list */
    throw new Error(`${provider} is not a valid credit card provider.`);
  } else if (!allCards.some(cardProvider => cardProvider.test(sanitized))) {
    // no specific provider
    return false;
  }
  return isLuhnValid(card);
}

View on GitHub (pinned to a79ff980ab)

Solutions

  1. Use one of the exact supported keys (lowercase, no spaces): amex, dinersclub, discover, jcb, mastercard, unionpay, visa, mir, elo, hipercard
  2. Normalize/trim your provider string before calling
  3. If the brand is not supported, call without a provider to validate against all cards
  4. Check the current cards table in src/lib/isCreditCard.js for the supported set in your version

Example fix

// before
validator.isCreditCard(num, 'Master Card'); // throws
// after
validator.isCreditCard(num, 'mastercard');
Defensive patterns

Strategy: validation

Validate before calling

const CARDS = ['amex','dinersclub','discover','jcb','mastercard','unionpay','visa','mir','elo','hipercard'];
const providerOk = (p) => !p || CARDS.includes(String(p).toLowerCase().trim());
if (!providerOk(provider)) throw new TypeError(`Unsupported provider: ${provider}`);

Type guard

const isCardProvider = (p) => typeof p === 'string' && CARDS.includes(p.toLowerCase().trim());

Try / catch

let ok;
try { ok = validator.isCreditCard(num, provider); }
catch (e) { if (/not a valid credit card provider/.test(e.message)) { ok = validator.isCreditCard(num); } else { throw e; } }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of validatorjs/validator.js@a79ff980ab (2026-08-31). Data as JSON: /api/errors/8b458c7231a09a09. Report an issue: GitHub.