Reputation: 187
I'm using the swiftValdator framework for iOS development. 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 ^(?=.*[a-z])(?=.*[A-Z])(?=.*[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:
Upvotes: 1
Views: 375
Reputation: 1308
The regex inside the "" isn't converted correctly, try this:
static let regex = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[,.:=+\\-_|)(%$#@!£/?`;&\"\\\\])[A-Za-z\\d,.:=+\\-_|)(%$#@!£/?`;&\"\\\\]{8,32}"
Upvotes: 1