1

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:

  1. Password must be between 8 and 32 characters in length.
  2. Password must contain any 3 of the following characters combinations:
    • 1 Uppercase (capital) letter [A-Z]
    • 1 Lowercase (common) letter [a-z]
    • 1 Number [0-9]
    • 1 Symbol [, . : = + - _ | ) ( % $ # @ ! £ / \ ? ` ; & "]
Laurel
  • 5,965
  • 14
  • 31
  • 57
Jurian Amatsahip
  • 187
  • 1
  • 2
  • 11

1 Answers1

1

The regex inside the "" isn't converted correctly, try this:

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