Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (BOOL)isValidCardNumber:(NSString *)number {
- NSInteger *length = number.length;
- int c = [[number substringWithRange:NSMakeRange(15, 1)] intValue];
- int s,k,d = 0;
- if (length < 16 || [[number substringWithRange:NSMakeRange(1, 10)] intValue] == 0 || [[number substringWithRange:NSMakeRange(10, 6)] intValue] == 0) {
- return false;
- }
- for (int i=0; i<16; i++) {
- k = (i % 2 == 0) ? 2 : 1;
- d = [[number substringWithRange:NSMakeRange(i, 1)] intValue] * k;
- s += (d > 9) ? d - 9 : d;
- }
- return ((s % 10) == 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement