pod "CreditCardValidator", '~> 0.5.3'
.package(url: "https://github.com/vitkuzmenko/CreditCardValidator.git", from: "0.5.3")
在您想要使用它的目标中指定 "CreditCardValidator"
作为依赖项后,运行 swift package update
。
执行与 SwiftPM 相同的配置,然后运行 accio update
而不是 swift package update
。
let number = "1234 5678 9123 4567"
if CreditCardValidator(number).isValid {
// Card number is valid
} else {
// Card number is invalid
}
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
}
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
}
非常欢迎贡献 👍😃。