...
|
...
|
@@ -165,6 +165,66 @@ function getAge(birthdate) { |
165
|
165
|
return age;
|
166
|
166
|
}
|
167
|
167
|
|
|
168
|
+//银行卡号码检测
|
|
169
|
+function banknoCheck(bankno) {
|
|
170
|
+ var lastNum = bankno.substr(bankno.length - 1, 1); //取出最后一位(与luhn进行比较)
|
|
171
|
+ var first15Num = bankno.substr(0, bankno.length - 1); //前15或18位
|
|
172
|
+ var newArr = new Array();
|
|
173
|
+ for (var i = first15Num.length - 1; i > -1; i--) { //前15或18位倒序存进数组
|
|
174
|
+ newArr.push(first15Num.substr(i, 1));
|
|
175
|
+ }
|
|
176
|
+ var arrJiShu = new Array(); //奇数位*2的积 <9
|
|
177
|
+ var arrJiShu2 = new Array(); //奇数位*2的积 >9
|
|
178
|
+ var arrOuShu = new Array(); //偶数位数组
|
|
179
|
+ for (var j = 0; j < newArr.length; j++) {
|
|
180
|
+ if ((j + 1) % 2 == 1) { //奇数位
|
|
181
|
+ if (parseInt(newArr[j]) * 2 < 9) arrJiShu.push(parseInt(newArr[j]) * 2);
|
|
182
|
+ else arrJiShu2.push(parseInt(newArr[j]) * 2);
|
|
183
|
+ } else //偶数位
|
|
184
|
+ arrOuShu.push(newArr[j]);
|
|
185
|
+ }
|
|
186
|
+
|
|
187
|
+ var jishu_child1 = new Array(); //奇数位*2 >9 的分割之后的数组个位数
|
|
188
|
+ var jishu_child2 = new Array(); //奇数位*2 >9 的分割之后的数组十位数
|
|
189
|
+ for (var h = 0; h < arrJiShu2.length; h++) {
|
|
190
|
+ jishu_child1.push(parseInt(arrJiShu2[h]) % 10);
|
|
191
|
+ jishu_child2.push(parseInt(arrJiShu2[h]) / 10);
|
|
192
|
+ }
|
|
193
|
+
|
|
194
|
+ var sumJiShu = 0; //奇数位*2 < 9 的数组之和
|
|
195
|
+ var sumOuShu = 0; //偶数位数组之和
|
|
196
|
+ var sumJiShuChild1 = 0; //奇数位*2 >9 的分割之后的数组个位数之和
|
|
197
|
+ var sumJiShuChild2 = 0; //奇数位*2 >9 的分割之后的数组十位数之和
|
|
198
|
+ var sumTotal = 0;
|
|
199
|
+ for (var m = 0; m < arrJiShu.length; m++) {
|
|
200
|
+ sumJiShu = sumJiShu + parseInt(arrJiShu[m]);
|
|
201
|
+ }
|
|
202
|
+
|
|
203
|
+ for (var n = 0; n < arrOuShu.length; n++) {
|
|
204
|
+ sumOuShu = sumOuShu + parseInt(arrOuShu[n]);
|
|
205
|
+ }
|
|
206
|
+
|
|
207
|
+ for (var p = 0; p < jishu_child1.length; p++) {
|
|
208
|
+ sumJiShuChild1 = sumJiShuChild1 + parseInt(jishu_child1[p]);
|
|
209
|
+ sumJiShuChild2 = sumJiShuChild2 + parseInt(jishu_child2[p]);
|
|
210
|
+ }
|
|
211
|
+ //计算总和
|
|
212
|
+ sumTotal = parseInt(sumJiShu) + parseInt(sumOuShu) + parseInt(sumJiShuChild1) + parseInt(sumJiShuChild2);
|
|
213
|
+
|
|
214
|
+ //计算luhn值
|
|
215
|
+ var k = parseInt(sumTotal) % 10 == 0 ? 10 : parseInt(sumTotal) % 10;
|
|
216
|
+ var luhn = 10 - k;
|
|
217
|
+
|
|
218
|
+ if (lastNum == luhn) {
|
|
219
|
+ // $("#banknoInfo").html("luhn验证通过");
|
|
220
|
+ return true;
|
|
221
|
+ } else {
|
|
222
|
+ // $("#banknoInfo").html("银行卡号必须符合luhn校验");
|
|
223
|
+ return false;
|
|
224
|
+ }
|
|
225
|
+}
|
|
226
|
+
|
|
227
|
+
|
168
|
228
|
module.exports = {
|
169
|
229
|
formatTime: formatTime,
|
170
|
230
|
formatTime_date: formatTime_date,
|
...
|
...
|
@@ -178,5 +238,6 @@ module.exports = { |
178
|
238
|
analyzeIDCard: analyzeIDCard,
|
179
|
239
|
checkNumber: checkNumber,
|
180
|
240
|
isMobile: isMobile,
|
181
|
|
- getAge: getAge
|
|
241
|
+ getAge: getAge,
|
|
242
|
+ banknoCheck: banknoCheck
|
182
|
243
|
} |
...
|
...
|
|