Swift Package Index



  • The latest stable release is 2.0.2. Released 8 months ago.
  • The last commit to master was 8 months ago.

Swift Version Compatibility

  • 2.0.2 and master
    5.3
    5.2
    5.1
    5.0
    4.2
Full build results

Platform Compatibility

  • 2.0.2 and master
    iOS
    macOS(Intel)
    macOS(ARM)
    Linux
    tvOS
    watchOS
Full build results

DECardNumberFormatter

Card brands

  • AmEx
  • DinersClub
  • Discover
  • JCB
  • MasterCard
  • UATP
  • UnionPay
  • Visa
  • Other

Formats

  • 4-5-6 • (4-5-6-4)
  • 4-6-4 • (4-6-5-4)
  • 4-6-5 • (4-6-5-4)
  • 4-4-4-4 • (4-4-4-4-3)

Integration

Swift Package Manager

You can use the Swift Package Manager to install DECardNumberFormatter by adding the following dependency to your Package.swift file:

.package(url: "https://github.com/Darkngs/DECardNumberFormatter.git", from: "2.0.0"),

Manually

Alternatively you can directly add the DECardNumberFormatter.swift & DECardNumberTextField.swift source files to your project.

Example - DECardNumberFormatter

let cardNumberFormatter = DECardNumberFormatter()

// AmEx
print(cardNumberFormatter.number(from: "34 12 123456 12345"))
print(cardNumberFormatter.number(from: "37 12 123456 12345"))

// Diners Club
var cardNumber = "300 1 123456 1234"
print(cardNumberFormatter.number(from: cardNumber))
if cardNumberFormatter.isValidLuhnCardNumber(cardNumber) {
   print("Card number: \(cardNumber) - is valid!")
}

// UATP
cardNumber = "1 234 12345 123456 1234"
print(cardNumberFormatter.number(from: cardNumber))
if cardNumberFormatter.isValidLuhnCardNumber(cardNumber) {
   print("Card number: \(cardNumber) - is valid!")
}

// Visa
cardNumber = "4111111111111111"
print(cardNumberFormatter.number(from: cardNumber))
if cardNumberFormatter.isValidLuhnCardNumber(cardNumber) {
   print("Card number: \(cardNumber) - is valid!")
}
Output
3412 123456 12345
3712 123456 12345
3001 123456 1234
1234 12345 123456 1234
4111 1111 1111 1111
Card number: 4111111111111111 - is valid!

Example - DECardNumberTextField

let textField = DECardNumberTextField()
textField.setup()