textField
在我之后
endEditing
由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法进行正则表达式匹配,原因:无法打开pattern U regex\U missmatched\U PAREN(string asdf,pattern^(?)?=.
[A-Z]。(?=.
static func isPasswordValid(_ password : String) -> Bool {
/*
^ Start anchor
(?=.*[A-Z].*[A-Z]) Ensure string has two uppercase letters.
(?=.*[!@#$&*]) Ensure string has one special case letter.
(?=.*[0-9].*[0-9]) Ensure string has two digits.
(?=.*[a-z].*[a-z].*[a-z]) Ensure string has three lowercase letters.
.{8} Ensure string is of length 8.
$ End anchor.
*/
let passwordTest = NSPredicate(format: "SELF MATCHES %@", "^(?=.*[A-Z].(?=.*[0-9].(?=.*[a-z].{8}$")
return passwordTest.evaluate(with: password)
}
我这样称呼它:
func textFieldShouldEndEditing(_ textField: UITextField) -> Bool {
if textField == passwordTextField {
if !Utilities.isPasswordValid(textField.text!){
self.passwordTextField.borderInactiveColor = .red
print("hi")
}
}
return true
}