|ReleasedLast Release||Mar 2017|
Maintained by Mariusz Wisniewski.
|LOCLines of Code||265|
CCValidator (we’re very proud of the unique name
Opposing to other existing validation libraries, this one doesn’t use Regex. It was inspired by CreditCardJS and its purpose it to provide a clear code, understanding which doesn’t require knowledge of regex – everyone should be able to read and edit validation code with ease.
Plus, ability to detect possible card type even from only first digit, lets you fail early.
This pod doesn’t contain an example app, but tests should show you how to use it properly.
To run the example project, clone the repo, and run
pod install from the Example directory first.
To get type from card prefix, pass credit card input you have (can be as short as 1 character string). Validator will check it against all types it knows and return recognized type, or .
NSString *numberAsString = textField.text; CreditCardType creditCardType = [CCValidator typeCheckingPrefixOnlyWithCreditCardNumber:cardNumber]; //check if type is e.g. CreditCardTypeVisa, CreditCardTypeMasterCard or CreditCardTypeNotRecognized
let numberAsString = textField.text let recognizedType = CCValidator.typeCheckingPrefixOnly(creditCardNumber: numberAsString) //check if type is e.g. .Visa, .MasterCard or .NotRecognized
You can also validate length and type – e.g. if validator recognizes card as MasterCard, it won’t validate cards with different length than 16 digits. For Visa, it will allow 13, 16 and 19 digits etc.
Next to that, it also validates card number using Luhn algorithm – this way you can pass to your payment processor only cards that numbers look like correct ones.
NSString *numberAsString = textField.text; BOOL isFullCardDataOK = [CCValidator validateWithCreditCardNumber:numberAsString];
let numberAsString = textField.text let isFullCardDataOK = CCValidator.validate(creditCardNumber: numberAsString)
This pod doesn’t have any extra dependencies.
CCValidator is available through CocoaPods. To install it, simply add the following line to your Podfile:
Mariusz Wisniewski, Digital Forms
CCValidator is available under the MIT license. See the LICENSE file for more info.