Swiftpack.co - vitkuzmenko/CreditCardValidator as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Credit Card Validator in Swift
.package(url: "https://github.com/vitkuzmenko/CreditCardValidator.git", from: "0.5.2")



pod "CreditCardValidator", '~> 0.5.2'

Swift Package Manager

.package(url: "https://github.com/vitkuzmenko/CreditCardValidator.git", from: "0.5.2")

After specifying "CreditCardValidator" as a dependency of the target in which you want to use it, run swift package update.


Do the same configurations as for SwiftPM, then run accio update instead of swift package update.



let number = "1234 5678 9123 4567"
if CreditCardValidator(number).isValid {
  // Card number is valid
} else {
  // Card number is invalid

Detect Card Type

let number = "1234 5678 9123 4567"
if let type = CreditCardValidator(number).type {
    print(type.name) // Visa, Mastercard, Amex etc.
} else {
    // I Can't detect type of credit card

Check type and validation

let number = "1234 5678 9123 4567"
if CreditCardValidator(number).isValid(for: .visa) {
    // Card number is valid and type is .visa
} else {
    // I Can't detect type of credit card

Supported types

  • Amex
  • Visa
  • MasterCard
  • Maestro
  • DinersClub
  • JCB
  • Discover
  • UnionPay
  • Mir


Contributions are very welcomed 👍😃.


Stars: 108
Last commit: Yesterday

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics