安装
CocoaPods
pod "CreditCardValidator", '~> 0.5.2'
Swift Package Manager
.package(url: "https://github.com/vitkuzmenko/CreditCardValidator.git", from: "0.5.2")
在您想要使用的目标中将 "CreditCardValidator"
指定为其依赖项后,运行 swift package update
.
Accio
与 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
}
支持的类型
- Amex
- Visa
- MasterCard
- Maestro
- DinersClub
- JCB
- Discover
- UnionPay
- Mir
贡献
非常欢迎贡献