forked from card-io/card.io-iOS-source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCardIOCVVTextFieldDelegate.m
36 lines (30 loc) · 1004 Bytes
/
CardIOCVVTextFieldDelegate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//
// CardIOCVVTextFieldDelegate.m
// See the file "LICENSE.md" for the full license governing this code.
//
#import "CardIOCVVTextFieldDelegate.h"
#import "CardIOCreditCardNumber.h"
@implementation CardIOCVVTextFieldDelegate
- (id)init {
if ((self = [super init])) {
self.numbersOnly = YES;
self.maxLength = 4;
}
return self;
}
- (void)setMaxLength:(NSInteger)maxLength {
if (maxLength <= 0 || 4 < maxLength) super.maxLength = 4;
else super.maxLength = maxLength;
}
+ (BOOL)isValidCVV:(NSString *)cvv forNumber:(NSString *)number {
CardIOCreditCardType cardType = [CardIOCreditCardNumber cardTypeForCardNumber:number];
if (cardType == CardIOCreditCardTypeUnrecognized || cardType == CardIOCreditCardTypeAmbiguous) {
return ([cvv length] >= 3); // no need to get overly fussy here...it's someone else's problem
}
NSInteger cvvLength = [CardIOCreditCardNumber cvvLengthForCardType:cardType];
if (cvvLength != [cvv length]) {
return NO;
}
return YES;
}
@end