I have a textField
into which the user types an email address. I want to activate the submit button at the instant the input text becomes a valid email address.
The validation works, but the code in shouldChangeCharactersInRange
appears to execute one step behind the user input. So when the email is valid, the user still has to tap one more key before the button changes. And likewise, if the email address becomes invalid, the button doesn't change until one more key is tapped.
Note that this happens on the device too, not just in the simulator.
Code is below:
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) {
if emailIsValidFormat(textField.text) {
emailSubmitButton.alpha = 1
} else {
emailSubmitButton.alpha = 0.4
}
}