dojox/validate/creditCard.js

  • Provides:

    • dojox.validate.creditCard
  • Requires:

    • dojox.validate._base in common
  • dojox.validate.creditCard

    • type
      Object
    • summary
      Module provides validation functions for Credit Cards, using account number
      rules in conjunction with the Luhn algorigthm, with a plugable card info database.
  • dojox.validate._cardInfo

    • type
      Object
    • summary
      A dictionary list of credit card abbreviations
    • description
      A hash of valid CC abbreviations and regular expressions
      
      mc: Mastercard
      ec: Eurocard
      vi: Visa
      ax: American Express
      dc: Diners Club
      bl: Carte Blanch
      di: Discover
      jcb: JCB
      er: Enroute
    • example
      Define your own card, gift-card, whatever. Starts with 7,
      is 15 total length.
      
       dojo.mixin(dojox.validate._cardInfo, {
       	"my":"7[0-9]{14}"
       });
  • dojox.validate.isValidCreditCard

    • type
      Function
    • parameters:
      • value: (typeof String|Int)
        A Value (credit card number) to validate
      • ccType: (typeof String)
        A credit-card abbreviation.
    • source: [view]
       return ((ccType.toLowerCase() == 'er' || dojox.validate.isValidLuhn(value)) &&
         dojox.validate.isValidCreditCardNumber(value, ccType.toLowerCase())); // Boolean
    • summary
      Validate a credit card number by type with Luhn checking.
    • description
      Checks if a credit card type matches the # scheme in a passed value, and if
      the Luhn checksum is accurate (unless its an Enroute card, in which case
      the checkSum is skipped), returning a Boolean to check against.
    • example
      
      	if(dojox.validate.isValidCreditCard("12345", "mc")){
      		console.log('inconceivable');
      	}
  • dojox.validate.isValidCreditCardNumber

    • type
      Function
    • parameters:
      • value: (typeof String|Int)
        CC #, white spaces and dashes are ignored
      • ccType: (typeof String)
        One of the abbreviation values in `dojox.validate._cardInfo` --
        if Omitted, function returns a `|` delimited string of matching card types,
        or false if no matches found.
    • source: [view]
       value = String(value).replace(/[- ]/g,''); //ignore dashes and whitespaces


       var cardinfo = dojox.validate._cardInfo, results = [];
       if(ccType){
        var expr = '^' + cardinfo[ccType.toLowerCase()] + '$';
        return expr ? !!value.match(expr) : false; // boolean
       }


       for(var p in cardinfo){
        if(value.match('^' + cardinfo[p] + '$')){
         results.push(p);
        }
       }
       return results.length ? results.join('|') : false; // String | boolean
    • summary
      Checks if value matches the pattern for that card or any card types if none is specified
    • returns
      boolean|String | boolean
  • dojox.validate.isValidCvv

    • type
      Function
    • parameters:
      • value: (typeof String|Int)
      • ccType: (typeof String)
    • source: [view]
       if(!dojo.isString(value)){
        value = String(value);
       }
       var format;
       switch (ccType.toLowerCase()){
        case 'mc':
        case 'ec':
        case 'vi':
        case 'di':
         format = '###';
         break;
        case 'ax':
         format = '####';
         break;
       }

       
       return !!format && value.length && dojox.validate.isNumberFormat(value, { format: format }); // Boolean
    • summary
      Validate the security code (CCV) for a passed credit-card type.
    • description
    • returns
      Boolean
  • dojox.validate

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary