Determine credit card type by number?

后端 未结 15 2034
旧巷少年郎
旧巷少年郎 2020-11-30 19:44

Can credit card type be determined solely from the credit card number?

Is this recommended or should we always ask client for the type of credit card they\'re using?

15条回答
  •  半阙折子戏
    2020-11-30 20:04

    here is the script that i use that works with current card ranges. also does a validity check on the number.

    /**
    * checks a given string for a valid credit card
    * @returns:
    *   -1  invalid
    *       1   mastercard
    *       2   visa
    *       3   amex
    *       4   diners club
    *       5   discover
    *       6   enRoute
    *       7   jcb
    */
    function checkCC(val) {
        String.prototype.startsWith = function (str) {
            return (this.match("^" + str) == str)
        }
    
        Array.prototype.has=function(v,i){
            for (var j=0;j

提交回复
热议问题