For anyone who is still looking for an answer to this, please have a look at the following framework;
It is a rule based validation framework, which handles most of the validations out of box. And top it all, it has form validator
which supports validation of multiple textfields at the same time.
For validating an email string, use the following;
"[email protected]".satisfyAll(rules: [StringRegexRule.email]).status
If you want to validate an email from textfield, try below code;
textfield.validationRules = [StringRegexRule.email]
textfield.validationHandler = { result in
// This block will be executed with relevant result whenever validation is done.
print(result.status, result.errors)
}
// Below line is to manually trigger validation.
textfield.validateTextField()
If you want to validate it while typing in textfield or when focus is changed to another field, add one of the following lines;
textfield.validateOnInputChange(true)
// or
textfield.validateOnFocusLoss(true)
Please check the readme file at the link for more use cases.