Latest 1.0.2
License MIT
Platforms ios 4.3, osx 10.6, requires ARC

Luhn Algorithm

Circle CI CocoaPods

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

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.


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



Name Website Reason
Paypal List of valid credit card numbers for the unit tests


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

Twitter: @ayanonagon


This project is licensed under the MIT License.

Latest podspec

    "name": "ObjectiveLuhn",
    "version": "1.0.2",
    "summary": "The Luhn Algorithm ported to objective-c.",
    "homepage": "",
    "license": "MIT",
    "authors": {
        "MaxKramer": "[email protected]"
    "source": {
        "git": "",
        "tag": "v1.0.2"
    "platforms": {
        "ios": "4.3",
        "osx": "10.6"
    "source_files": [
        "Algorithm\ Class",
        "Algorithm\ Class/*.{h,m}"
    "requires_arc": true

Pin It on Pinterest

Share This