DECardNumberFormatter

master

Darkngs/DECardNumberFormatter

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()

Description

  • Swift Tools 5.2.0
View More Packages from this Author

Dependencies

  • None
Last updated: Thu Nov 10 2022 07:50:45 GMT-0500 (GMT-05:00)