使用swiftvalidator的swift正则表达式出错



我正在使用swiftValdator框架进行iOS开发。我用正则表达式创建了一个自定义验证器类。

错误为:

'NSInternalInconsistencyException', reason: 'Can't do regex matching, reason: Can't open pattern U_REGEX_MISSING_CLOSE_BRACKET (string lol, pattern ^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[,.:=+-_|)(%$#@!£/?';&"])[A-Za-z0-9,.:=+-_|)(%$#@!]£/?';&"]{8,32}, case 0, canon 0)'

这是我的代码:

import Foundation
import SwiftValidator
class CustomPasswordRule: RegexRule {
    //^(?=.*[a-z])(?=.*[A-Z])(?=.*d)(?=.*[,.:=+-_|)(%$#@!£/?`;&"\])[A-Za-zd,.:=+-_|)(%$#@!£/?`;&"\]{8,32}
    static let regex = "^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[,.:=+-_|)(%$#@!£/?';&"\])[A-Za-z0-9,.:=+-_|)(%$#@!]£/?';&"\]{8,32}"
    convenience init(message: String = "Not a valid Password") {
        self.init(regex: CustomPasswordRule.regex,message: message)
    } 
}

有人能帮我纠正这个错误吗?以下是条件:

  1. 密码的长度必须在8到32个字符之间
  2. 密码必须包含以下任意3个字符组合:
    • 1大写字母[A-Z]
    • 1小写(常用)字母[a-z]
    • 1个数字[0-9]
    • 1符号[,.:=+-_|)(%$#@!£/\?`;&"]

"中的正则表达式未正确转换,请尝试以下操作:

static let regex = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[,.:=+\-_|)(%$#@!£/?`;&"\\])[A-Za-z\d,.:=+\-_|)(%$#@!£/?`;&"\\]{8,32}"

最新更新