0
At least one digit [0-9]
At least one lowercase character [a-z]
At least one uppercase character [A-Z]
At least one special character [*.!@#$%^&(){}[]:;<>,.?/~_+-=|\]
At least 8 characters in length, but no more than 32.

I have regex.

"^(?=.[a-z])(?=.[A-Z])(?=.\d)(?=.[*.!@#$%^&(){}[]:;<>,.?/~_+-=|]{8,32}$"

   var isPasswordValid: Bool {
        let passwordRegEx = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[*.!@#$%^&(){}[]:;<>,.?/~_+-=|\\]{8,32}$"
        return NSPredicate(format: "SELF MATCHES %@", passwordRegEx).evaluate(with: self)
    }

Swift show me the error: Invalid escape sequence in literal

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Can't do regex matching, reason: Can't open pattern U_REGEX_MISSING_CLOSE_BRACKET (string , pattern ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[*.!@#$%^&(){}[]:;<>,.?/~_+-=|\]{8,32}$, case 0, canon 0)'
terminating with uncaught exception of type NSException
CoreSimulator 772.1 - Device: iPhone 12 Pro Max (A3ED8F9E-6E9C-4348-AEB6-52C73DB210C0) - Runtime: iOS 14.5 (18E182) - DeviceType: iPhone 12 Pro Max
kakashi333
  • 23
  • 4

0 Answers0