ios - 如何在 Swift 中使用常规表达式设置信用卡 PAN NUMBER 的模式?

标签 ios swift credit-card banking

我正在尝试使用 Vision Framework 从实体信用卡中读取泛号。为此,我使用字符串扩展来过滤结果。

以下是美国电话号码的示例:

func extractPhoneNumber() -> (Range<String.Index>, String)? {
        let pattern = #"""
        (?x)                    # Verbose regex, allows comments
        (?:\+1-?)?              # Potential international prefix, may have -
        [(]?                    # Potential opening (
        \b(\w{3})               # Capture xxx
        [)]?                    # Potential closing )
        [\ -./]?                # Potential separator
        (\w{3})                 # Capture xxx
        [\ -./]?                # Potential separator
        (\w{4})\b               # Capture xxxx
        """#

        guard let range = self.range(of: pattern, options: .regularExpression, range: nil, locale: nil) else {
            // No phone number found.
            return nil
        }

我需要以下形式的卡盘编号的不同模式,例如。 0000 0000 0000 0000

谢谢您的帮助!

最佳答案

对我有用的模式是:

let pattern = #"""
        \d{4} \d{4} \d{4} \d{4}
        """#

谢谢脚本!

关于ios - 如何在 Swift 中使用常规表达式设置信用卡 PAN NUMBER 的模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58995572/

相关文章:

iphone - 如何在屏幕解锁后重新启动动画

ios - CLLocationDistance 不起作用 - 快速

ios - 如何在自定义相机中实现 "pinch to zoom"

ios - Swift:在 UITableViewCell 中异步加载图像 - 自动布局问题

Angular 2 : add hyphen after every 4 digit in input , 卡号输入

ios - 如果我支持 iOS 3.x,Apple 会拒绝我们的应用程序吗?

ios - APNS Provider API 和 Postman

ios - 随机生成的数组仅适用于按钮

credit-card - EMV:从 ICC 获取 CVV 代码?

sql - 查找并替换信用卡号码