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 [, . : = + - _ | ) ( % $ # @ ! £ / \ ? ` ; & "]
1

1 Answer 1

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}"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.