JS检验用户输入的银行卡号的合法性,搜索后都说采用Luhn算法进行校验,Luhn算法介绍可见这位博友https://www.jianshu.com/p/193...,JS代码实现如下:function acount_check(cardNum) { if(!cardNum) return false; let len = cardNum.length; let carNumArr = Array.from(cardNum.slice(0,len)); let tem = 0; for(let i = len-2;i>=0;i-=2){ tem = parseInt(cardNum[i])*2; carNumArr[i] = Math.floor(tem/10) + tem%10; } let result = 0; carNumArr.forEach(val => { result+=parseInt(val); }) return result%10 == 0;};经检测,部分银行卡号并不符合上面的算法规则,检测数据为下述链接:https://www.qusocha.com/bank/1/如:该卡号返回false:(6217003480001296493),在线银行卡号查询网站http://www.cardcn.com/search....查询后,确实存在该卡号。请问各位码友们有什么好的解决方案码?
添加回答
举报
0/150
提交
取消