Swiftpack.co - spothero/SpotHeroEmailValidator-iOS as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by spothero.
spothero/SpotHeroEmailValidator-iOS v1.0.4
iOS Email Validator
⭐️ 116
🕓 3 weeks ago
iOS macOS tvOS
.package(url: "https://github.com/spothero/SpotHeroEmailValidator-iOS.git", from: "v1.0.4")


CI Status Latest Release Swift Version Platform Support License

An iOS library that will provide basic email syntax validation as well as provide suggestions for possible typos (for example, [email protected] would be corrected to [email protected]).


Typo correction suggestion Basic syntax validation Typo correction suggestion


UITextField subclass

The SHEmailValidationTextField class is a pre-built UITextField subclass that will automatically validate its own input when it loses focus (such as when the user goes from the email field to the password field). If a syntax error is detected, a popup will appear informing the user that the email address they entered is invalid. If a probably typo is detected, a popup will appear that allows the user to accept the suggestion or dismiss the popup. Using this class is as simple as replacing instances of UITextField with SHEmailValidationTextField.


To customize the default error message that appear for validation errors, use the setDefaultErrorMessage: method. To set specific messages for specific errors, use the setMessage:forErrorCode: method. To customize the text that appears above a typo suggestion, use the setMessageForSuggestion: method.

To customize the look and feel of the popup window that appears, the fillColor, titleColor, and suggestionColor properties can be set as desired.

Basic syntax checking

NSError *error = nil;
[[[SpotHeroEmailValidator] validator] validateSyntaxOfEmailAddress:emailAddress withError:&error];

if (error) {
	// An error occurred
	switch (error.code) {
		case SHBlankAddressError:
			// Input was empty
		case SHInvalidSyntaxError:
			// Syntax completely wrong (probably missing @ or .)
		case SHInvalidUsernameError:
			// Local portion of the email address is empty or contains invalid characters
		case SHInvalidDomainError:
			// Domain portion of the email address is empty or contains invalid characters
		case SHInvalidTLDError:
			// TLD portion of the email address is empty, contains invalid characters, or is under 2 characters long
} else {
	// Basic email syntax is correct

Get typo correction suggestion

NSError *error = nil;
NSString *suggestion = [[[SpotHeroEmailValidator] validator] autocorrectSuggestionForEmailAddress:emailAddress withError:&error];

if (error) {
	// The syntax check failed, so no suggestions could be generated
} else if (suggestion) {
	// A probable typo has been detected and the suggestion variable holds the suggested correction
} else {
	// No typo was found, or no suggestions could be generated

Updating the IANA TLD list

To fetch the latest IANA TLDs, run the following script included in the root directory: fetch_iana_list.rb

This will update the plist under SpotHeroEmailValidator/DomainData.plist The script requires the httparty and plist Ruby gems to be installed.


SpotHeroEmailValidator uses ARC. If your project is not ARC-compliant, simply set the -fobjc-arc flag on all SpotHeroEmailValidator source files.

Apps Using this Library

This library is used in our own SpotHero iOS app. If you would like to see your app listed here as well, let us know you're using it!


SpotHeroEmailValidator is released under the Apache 2.0 license.


Stars: 116
Last commit: 3 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

3 weeks ago

Adds Email and EmailComponents models for simpler email validation and parsing

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics