Need help with ObjectiveLuhn?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

maxkramer
125 Stars 20 Forks MIT License 80 Commits 1 Opened issues

Description

Luhn Credit Card Validation Algorithm

Services available

!
?

Need anything else?

Contributors list

# 46,653
Objecti...
Swift
carthag...
digest
5 commits
# 496,806
Objecti...
Ruby
3 commits

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/enUS/vhelp/paypalmanagerhelp/creditcardnumbers.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.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.