简体   繁体   English

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

[英]Error with swift regex using swiftvalidator?

I'm using the swiftValdator framework for iOS development.我正在使用 swiftValdator 框架进行 iOS 开发。 I created a custom validator class with a regex.我用正则表达式创建了一个自定义验证器类。

The error is:错误是:

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

This is my code:这是我的代码:

import Foundation
import SwiftValidator

class CustomPasswordRule: RegexRule {
    //^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[,.:=+\-_|)(%$#@!£/?`;&"\\])[A-Za-z\d,.:=+\-_|)(%$#@!£/?`;&"\\]{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)
    } 
}

Can anyone help me with the error?谁能帮我解决这个错误? These are the conditions:这些是条件:

  1. Password must be between 8 and 32 characters in length.密码长度必须在 8 到 32 个字符之间。
  2. Password must contain any 3 of the following characters combinations:密码必须包含以下任意 3 个字符组合:
    • 1 Uppercase (capital) letter [AZ] 1 大写(大写)字母 [AZ]
    • 1 Lowercase (common) letter [az] 1 小写(常用)字母 [az]
    • 1 Number [0-9] 1 号码 [0-9]
    • 1 Symbol [, . 1 符号 [, . : = + - _ | : = + - _ | ) ( % $ # @ ! £ / \\ ? ` ; & "] ) ( % $ # @ ! £ / \\ ? ` ; & "]

"" 中的正则表达式没有正确转换,试试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM