How to use card-validator - 10 common examples

To help you get started, we’ve selected a few card-validator examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github braintree / braintree-web / src / hosted-fields / internal / models / credit-card-form.js View on Github external
CreditCardForm.prototype._validateNumber = function (value) {
  var validationResult = validator.number(value, {
    luhnValidateUnionPay: true,
    maxLength: this.configuration.fields.number.maxCardLength
  });
  var card = validationResult.card;
  var possibleCardTypes, possibleCardType;

  // NEXT_MAJOR_VERSION credit-card-type fixed the mastercard enum
  // but we still pass master-card in the braintree API
  // in a major version bump, we can remove this and
  // this will be mastercard instead of master-card
  if (card && card.type === 'mastercard') {
    card.type = 'master-card';
  }

  possibleCardTypes = this.getCardTypes(value).filter(function (cardType) {
    return card && cardType.type === card.type;
github braintree / braintree-web / src / hosted-fields / internal / models / credit-card-form.js View on Github external
CreditCardForm.prototype._validateCvv = function (value, options) {
  var cvvSize, minLength;

  options = options || {};
  minLength = options.minLength;

  if (this._fieldKeys.indexOf('number') === -1) { // CVV only
    return validator.cvv(value, minLength || [3, 4]);
  }

  cvvSize = this.get('possibleCardTypes').map(function (item) {
    return item.code.size;
  });
  cvvSize = uniq(cvvSize);

  return validator.cvv(value, cvvSize);
};
github braintree / braintree-web / src / hosted-fields / internal / models / credit-card-form.js View on Github external
CreditCardForm.prototype._validateCvv = function (value, options) {
  var cvvSize, minLength;

  options = options || {};
  minLength = options.minLength;

  if (this._fieldKeys.indexOf('number') === -1) { // CVV only
    return validator.cvv(value, minLength || [3, 4]);
  }

  cvvSize = this.get('possibleCardTypes').map(function (item) {
    return item.code.size;
  });
  cvvSize = uniq(cvvSize);

  return validator.cvv(value, cvvSize);
};
github bigcommerce / checkout-sdk-js / src / hosted-form / iframe-content / hosted-input-validator.ts View on Github external
test(value) {
                    const { card } = number((this.parent as HostedInputValues).cardNumber);

                    return cvv(value, card && card.code ? card.code.size : undefined).isValid;
                },
            });
github bigcommerce / checkout-sdk-js / src / hosted-form / iframe-content / hosted-input-validator.ts View on Github external
test(value) {
                    const { card } = number((this.parent as HostedInputValues).cardNumber);

                    return cvv(value, card && card.code ? card.code.size : undefined).isValid;
                },
            });
github Syncano / syncano-dashboard / src / apps / Profile / ProfileBillingPayment.jsx View on Github external
onCardNumberChange(event, value) {
    const numberValidation = valid.number(_.camelCase(value));
    const niceType = numberValidation.card ? numberValidation.card.niceType : null;

    this.setState({
      number: value,
      cardNiceType: niceType
    });
  },
github bigcommerce / checkout-sdk-js / src / hosted-form / iframe-content / hosted-card-number-input.ts View on Github external
protected _notifyChange(value: string): void {
        const cardInfo = number(value).card;
        const prevCardInfo = this._previousValue && number(this._previousValue).card;

        if (get(prevCardInfo, 'type') === get(cardInfo, 'type')) {
            return;
        }

        this._eventPoster.post({
            type: HostedInputEventType.CardTypeChanged,
            payload: {
                cardType: cardInfo ? cardInfo.type : undefined,
            },
        });
    }
github bigcommerce / checkout-sdk-js / src / hosted-form / iframe-content / hosted-card-number-input.ts View on Github external
protected _notifyChange(value: string): void {
        const cardInfo = number(value).card;
        const prevCardInfo = this._previousValue && number(this._previousValue).card;

        if (get(prevCardInfo, 'type') === get(cardInfo, 'type')) {
            return;
        }

        this._eventPoster.post({
            type: HostedInputEventType.CardTypeChanged,
            payload: {
                cardType: cardInfo ? cardInfo.type : undefined,
            },
        });
    }
github madmath / payment-request-show / bobpay / public / pay / bundled-card-validator.js View on Github external
function cardInfoUpdated(event) {
  var name = document.getElementById("full-name").value;
  var expDate = document.getElementById("exp-date").value;
  var number = document.getElementById("cc-number").value;

  var validationResult = cardValidator.number(number);
  var expDateValidation = cardValidator.expirationDate({ month: expDate.substring(5) , year: expDate.substring(0, 4) });

  var readyToSave = validationResult.isValid && expDateValidation.isValid && name.length > 0;
  document.getElementById("add-card-confirm-button").disabled = !readyToSave;

  var formattedNumber = formatCardNumber(number);
  if (number !== formattedNumber) {
    document.getElementById("cc-number").value = formattedNumber;
  }
}

card-validator

A library for validating credit card fields

MIT
Latest version published 1 day ago

Package Health Score

80 / 100
Full package analysis

Similar packages