我如何将这些函数组合到一个假的setregisterButton(enabled)
也是假的setregisterButton(enabled: false)
。我把它放在密码匹配方法之后就可以了,但是如果我决定更改原始密码,我想再次取消选择按钮。
这也不是主题,但有没有办法检查Firebase中是否已经使用过电子邮件?
@IBAction func validatePasswordField() {
validatePasswordTextFieldWithText(password: passwordField.text)
}
func validatePasswordTextFieldWithText(password: String?) {
guard let password2 = password else {
passwordField.errorMessage = nil
return
}
if password2.isEmpty {
passwordField.errorMessage = nil
} else if !validatePassword(password2: password2) {
passwordField.errorMessage = NSLocalizedString(
"Password must be 8 characters long with an uppercase and
number",
tableName: "SkyFloatingLabelTextField",
comment: " "
)
} else {
passwordField.errorMessage = nil
}
}
func validatePassword(password2:String?) -> Bool {
// at least one uppercase,
// at least one digit
// at least one lowercase
// 8 characters total
let passwordTest = NSPredicate(format: "SELF MATCHES %@", "(?=.*[A-
Z])(?=.*[0-9])(?=.*[a-z]).{8,}")
return passwordTest.evaluate(with: password2)
}
@IBAction func validatePasswordMatch() {
validatePasswordMatchWithText(password: RetypepasswordField.text)
}
func validatePasswordMatchWithText(password: String?) {
guard let password4 = password else {
RetypepasswordField.errorMessage = nil
return
}
if password4.isEmpty {
RetypepasswordField.errorMessage = nil
} else if !validatePasswordMatch(password3: password4) {
RetypepasswordField.errorMessage = NSLocalizedString(
"Passwords do not match",
tableName: "SkyFloatingLabelTextField",
comment: " "
)
} else {
RetypepasswordField.errorMessage = nil;
setregisterButton(enabled: true)
}
}
func validatePasswordMatch(password3:String?) -> Bool {
let pass = passwordField.text
let pass2 = RetypepasswordField.text
let actualPassword = (pass == pass2)
return actualPassword
}