判断银行卡号是否有效
+ (BOOL) isValidCreditNumber:(NSString*)value {
02.
BOOL result = NO;
03.
NSInteger length = [value length];
04.
if
(length >=
13
) {
05.
result = [WTCreditCard isValidNumber:value];
06.
if
(result)
07.
{
08.
NSInteger twoDigitBeginValue = https://www.it610.com/article/[[value substringWithRange:NSMakeRange(
0
,
2
)] integerValue];
09.
//VISA
10.
if
([WTCreditCard isStartWith:value Str:@
"4"
]) {
11.
if
(
13
== length||
16
== length) {
12.
result = TRUE;
13.
}
else
{
14.
result = NO;
15.
}
16.
}
17.
//MasterCard
18.
else
if
(twoDigitBeginValue >=
51
&& twoDigitBeginValue <=
55
&& length ==
16
) {
19.
result = TRUE;
20.
}
21.
//American Express
22.
else
if
(([WTCreditCard isStartWith:value Str:@
"34"
]||[WTCreditCard isStartWith:value Str:@
"37"
]) && length ==
15
){
23.
result = TRUE;
24.
}
25.
//Discover
26.
else
if
([WTCreditCard isStartWith:value Str:@
"6011"
] && length ==
16
) {
27.
result = TRUE;
28.
}
else
{
29.
result = FALSE;
30.
}
31.
}
32.
if
(result)
33.
{
34.
NSInteger digitValue;
35.
NSInteger checkSum =
0
;
36.
NSInteger index =
0
;
37.
NSInteger leftIndex;
38.
//even length, odd index
39.
if
(
0
== length%
2
) {
40.
index =
0
;
41.
leftIndex =
1
;
42.
}
43.
//odd length, even index
44.
else
{
45.
index =
1
;
46.
leftIndex =
0
;
47.
}
48.
while
(index < length) {
49.
digitValue = https://www.it610.com/article/[[value substringWithRange:NSMakeRange(index,
1
)] integerValue];
50.
digitValue = https://www.it610.com/article/digitValue*
2
;
51.
if
(digitValue >=
10
)
52.
{
53.
checkSum += digitValue/
10
+ digitValue%
10
;
54.
}
55.
else
56.
{
57.
checkSum += digitValue;
58.
}
59.
digitValue = https://www.it610.com/article/[[value substringWithRange:NSMakeRange(leftIndex,
1
)] integerValue];
60.
checkSum += digitValue;
61.
index +=
2
;
62.
leftIndex +=
2
;
63.
}
64.
result = (
0
== checkSum%
10
) ? TRUE:FALSE;
65.
}
66.
}
else
{
67.
result = NO;
68.
}
69.
return
result;
70.
}
推荐阅读
- C语言解方程的根和判断是否是闰年
- 对今年以来股市的看法及后期判断
- vue中的条件判断详解v-if|vue中的条件判断详解v-if v-else v-else-if v-show
- Java应该在哪里判断List是否为空
- JavaScript判断数组的方法总结与推荐
- 借呗用户被银行拉黑贷不到款(马云(怪我咯?))
- 有声阅读2021-05-18
- 爱情银行中需要不定期存款
- 给老板选择题而不是问答题或判断题
- 判断scroll向上还是向下