• This repository has been archived on 10/Apr/2023
  • Stars
    star
    127
  • Rank 281,974 (Top 6 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created almost 12 years ago
  • Updated about 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Luhn Credit Card Validation Algorithm

Luhn Algorithm

Circle CI CocoaPods

This is a port of the Luhn Algorithm, generally used for validating Credit Card details, to Objective-C (iOS).

Swift port can be found at https://github.com/MaxKramer/SwiftLuhn.

It's as simple as calling one single method; no special formatting is required.

You must run pod install before opening the Example Project's 'workspace.

Instructions

Import the header:

#import "Luhn.h"

Call the class method returning a BOOL as to whether the string is valid or not:

BOOL isValid = [Luhn validateString:@"some credit card number"];
    
if (isValid) {
    // process payment   
}
else {
    // alert user
}

Alternatively, you can use the NSString category (no additional imports required):

NSString *ccNumber = @"378282246310005";
BOOL isValid = [ccNumber isValidCreditCardNumber];

You can also get the type of the credit card i.e. Visa, Diners, Amex, etc:

OLCreditCardType cardType = [ccNumber creditCardType];
// or
OLCreditCardType cardType = [Luhn typeFromString:ccNumber];

If you come across any issues or have a feature request, please open an issue or find me on:

Twitter: @maxkramer

Website: http://maxkramer.co

Sources

Name Website Reason
Paypal http://www.paypalobjects.com/en_US/vhelp/paypalmanager_help/credit_card_numbers.htm List of valid credit card numbers for the unit tests

Thanks

Ayaka Nonaka for updating the Cocoapod spec and helping me with other aspects of the project!

Twitter: @ayanonagon

License

This project is licensed under the MIT License.

More Repositories

1

SwiftLuhn

Debit/Credit card validation port of the Luhn Algorithm in Swift
Swift
135
star
2

CINBouncyButton

UIButton, but bouncier and with your own icons.
Objective-C
25
star
3

UIImageView-MKAsynchrony

Easy to implement alternative to AFNetworking's UIImageView+AFNetworking.
Objective-C
13
star
4

Easy-JSON-for-iOS-5

This helper class allows you to easily make use of the JSON functions found in the iOS 5 SDK, by adding a JSONValue category to NSString and NSData. This is a substitute for using SBJSON and JSONKit and uses NSJSONSerialization.
Objective-C
7
star
5

SCRProfanityChecker

Checks for profanity in a given file or string.
Objective-C
6
star
6

SCRSidewaysBarGraph

A sideways bar graph for iOS.
Objective-C
5
star
7

NetworkKit

iOS Async Networking Library with Stubbed Requests
Objective-C
5
star
8

URL-Shortener

A easy to use PHP & MySQL URL Shortener.
PHP
4
star
9

TMLanguageExtractor

Extract the syntax files from Sublime Text (2|3)
Python
4
star
10

MKImageDownloader

Asynchronous Image Downloader for iOS
Objective-C
4
star
11

Timber

Timber is a lightweight and flexible logging framework written in Swift
Swift
4
star
12

BlockUIAlertViewActionSheet

UIAlertView & UIActionSheet subclasses using Blocks rather than delegate callbacks
Objective-C
3
star
13

MKReachableOperationQueue

An NSOperationQueue subclass automatically responding to changes in internet connection with thanks to Apple's Reachability.
Objective-C
3
star
14

kotlin-starter

Starter project for Spring Boot with Kotlin
Kotlin
2
star
15

NSStringDrawingSizeMethod

Small category which can easily determine the height of a string. Replaces deprecated sizeWithFont... in iOS 7.
Objective-C
2
star
16

MontyHall

Monty Hall problem in Objective-C
Objective-C
1
star
17

RTFDiskCache

Read/Write Objects to/from disk
Objective-C
1
star
18

Butler

Swift
1
star
19

dotfiles

Dotfiles
Python
1
star
20

kramer.so

My personal website
TypeScript
1
star
21

Xcode4-Templates

Personally edited Xcode 4 Objective-C Class templates
Objective-C
1
star
22

Zeus

Zeus: God of the Cloud. A basic server setup script.
Shell
1
star
23

workflow-watcher

Simple Golang utility for listening on changes to Argo workflows.
Go
1
star