1、先引入jquery.js 2、接著引入luhmCheck.js //銀行卡號Luhm校驗 3、看下麵的案例: 下麵是js 測試卡號: 1、6222600810010710887 2、6225881414207430 ...
1、先引入jquery.js
2、接著引入luhmCheck.js //銀行卡號Luhm校驗
3、看下麵的案例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>無標題頁</title> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/luhmCheck.js"></script> </head> <body> <input type="text" id="t_bankno" /> <input type="button" id="btnCheck" value="check" onclick="CheckBankNo($('#t_bankno'));" /> <span id="banknoInfo"></span> </body> </html>
下麵是js
<script type="text/javascript">
function CheckBankNo(t_bankno) { var bankno = $.trim(t_bankno.val()); if(bankno == "") { $("#banknoInfo").html("請填寫銀行卡號"); return false; } if(bankno.length < 16 || bankno.length > 19) { $("#banknoInfo").html("銀行卡號長度必須在16到19之間"); return false; } var num = /^\d*$/; //全數字 if(!num.exec(bankno)) { $("#banknoInfo").html("銀行卡號必須全為數字"); return false; } //開頭6位 var strBin = "10,18,30,35,37,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,58,60,62,65,68,69,84,87,88,94,95,98,99"; if(strBin.indexOf(bankno.substring(0, 2)) == -1) { $("#banknoInfo").html("銀行卡號開頭6位不符合規範"); return false; } //Luhm校驗(新) if(!luhmCheck(bankno)) return false; $("#banknoInfo").html("驗證通過!"); return true; } </script>
測試卡號:
1、6222600810010710887
2、6225881414207430