前端开发银行卡号(bin码)识别发卡行

物流网站的前端开发 ui设计网站前端开发 asp.net前端开发网站

GitHub地址:https://github.com/Pasturn/cardNumQuery

(function ($) {
$.fn.cncard = function(options){
var container = $(this);

     options = $.extend({
        display:''
     },options);

     var display=options.display;

     function cardFormBank(num){

            var cards = [
            {
                bankName:'中国建设银行',
                pattern:/^(436742|436745|622280|622700)/g
            },
            {
                bankName:'交通银行',
                pattern:/^(458123|521899|622260|622250|622251|622258|622259)/g
            },
            {
                bankName:'上海银行',
                pattern:/^(402674|622892)/g
            },
            {
                bankName:'中国邮政储蓄银行',
                pattern:/^(622188|622150|622151|622199|955100)/g
            },
            {
                bankName:'北京银行',
                pattern:/^(602969)/g
            },
            {
                bankName:'中国银行',
                pattern:/^(622760|622751|622752|622753|622754|622755|622756|622757|622758|622759|622760|622761|622762|622763|409666|438088|601382)/g
            },
            {
                bankName:'中国工商银行',
                pattern:/^(427010|427018|427019|427020|427028|427029|427030|427038|427039|427062|427064|438125|438126|402791|530990|622230|622235|622210|622215|622200|622202|622203|622208|955880|370246|370247)/g
            },
            {
                bankName:'广发银行',
                pattern:/^(622568|520152|520382|911121|548844)/g
            },
            {
                bankName:'宁波银行',
                pattern:/^(512431|520194|622318|622778|622282)/g
            },
            {
                bankName:'中国民生银行',
                pattern:/^(512466|415599|421870|407405|517636|528948 |552288|556610|622600|622601|622602|622603|421869|421871|628258)/g
            },
            {
                bankName:'浦发银行',
                pattern:/^(418152|456418|622521|404738|404739|498451|622517|622518|515672|517650|525998|356850|356851|356852)/g
            },
            {
                bankName:'深圳发展银行',
                pattern:/^(435744|622526|435745|998801|998802|622525|622538)/g
            },
            {
                bankName:'中国光大银行',
                pattern:/^(406254|622655|622650|622658|356839|486497|481699|543159|425862|406252|356837|356838|356840|622161|628201|628202)/g
            },
            {
                bankName:'平安银行',
                pattern:/^(622155|622156|528020|526855)/g
            },
            {
                bankName:'华夏银行',
                pattern:/^(539867|528709|523959|622637|622636|528708|539868)/g
            },
            {
                bankName:'招商银行',
                pattern:/^(518710|518718|622588|622575|545947|521302|439229|552534|622577|622579|439227|479229|356890|356889|356885|439188|545948|545623|552580|552581|552582|552583|552584|552585|552586|552588|552589|645621|545619|356886|622578|622576|622581|439228|439225|439226|628262|628362)/g
            },
            {
                bankName:'中信银行',
                pattern:/^(376968|376966|622918|622916|518212|622690|520108|376969|622919|556617|622680|403391|558916|514906|400360|433669|433667|433666|404173|404172|404159|404158|403393|403392|622689|622688|433668|404157|404171|404174|628209|628208|628206)/g
            },
            {
                bankName:'中国农业银行',
                pattern:/^(552599|404119|404121|519412|403361|558730|520083|520082|519413|404120|622922|404118|404117|622836|622837|622848)/g
            },
            {
                bankName:'兴业银行',
                pattern:/^(451289|622902|622901|527414|524070|486493|486494|451290|523036|486861|622922 )/g
            }
        ];

            //循环查询银行,存在则返回该银行的数组
        for(var _i = 0,_len = cards.length; _i<_len;_i++)

            {   
                var card = cards[_i];
                if(card.pattern.test(num))
                {
                    return card;
                };
            };

            //循环结束,无相关数据,则返回false
            if(_i=_len)
                {
                    return false;
                };
        };

     function checkCardNum(e){
            //输入的卡号变为字符串同时截取前六位
            var cardNum = e.toString().substring(0,6);
            //变为数字
            cardNum = parseInt(cardNum);
            //进入cardFormBank()函数进行查询
            var a = cardFormBank(cardNum);
            //若无相关数据返回false,显示其他银行,否则返回银行名称
            if(a == false)
                {
                    return "其他银行" ;
                }
            else
                {
                    return a.bankName;
                }
        };

    $(container).change(function(){ 
            //获取输入框的银行卡号
            var num = $(this).val();
            //检测是否为数字且大于16位小于19位,否则显示输入有误
            if(!isNaN(num) && num.length>=16 && num.length<=19)
            {
                var result=checkCardNum(num);
                $(display).html(result);
            }
            else
            {
                $(display).html("输入有误");
            }
        });

};

})(jquery);
html部分只做展示
<!DOCTYPE html>
<html>
<head>
<meta http-equiv=”content-type” content=”text/html;charset=utf-8″>
<title></title>
<script type=”text/javascript” src=”http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js”></script>
<script type=”text/javascript” src=”cncard.js”></script>
<script type=”text/javascript”>
$(document).ready(function() {
$(‘#cardNum’).cncard({display:’#showarea’});
});
</script>
</head>
<body>
<input id=”cardNum” type=”text” name=”cardNum”/>
<div id=”showarea”></div>
</body>
</html>

网站前端开发与后台架构 html前端网站开发 前端开发常用的网站

» 本文来自:前端开发者 » 《前端开发银行卡号(bin码)识别发卡行》
» 本文链接地址:https://www.rokub.com/5554.html
» 您也可以订阅本站:https://www.rokub.com
赞(0)
64K

评论 抢沙发

评论前必须登录!