Git Product home page Git Product logo

objectiveluhn's Introduction

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.

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.

objectiveluhn's People

Contributors

ayanonagon avatar taemooncho avatar maxkramer avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.