SHEmailValidator 1.0.6

SHEmailValidator 1.0.6

测试已测试
语言语言 Obj-CObjective C
许可证 Apache-2.0
发布最后发布2019年10月

SpotHero iOS 团队 维护。




  • spothero 和 EricKuck

SHEmailValidator

这是一个 iOS 库,它将为基本的电子邮件语法验证提供支持,并为可能的错误(如,[email protected] 将被更正为 [email protected])提供建议。

截图

Typo correction suggestion Basic syntax validation Typo correction suggestion

用法

UITextField 子类

SHEmailValidationTextField 类是一个预构建的 UITextField 子类,当它失去焦点时会自动验证自己的输入(例如,当用户从电子邮件字段切换到密码字段时)。如果检测到语法错误,将弹出一个窗口通知用户他们输入的电子邮件地址无效。如果检测到可能拼写错误,将弹出一个窗口允许用户接受建议或关闭窗口。使用这个类就像将 UITextField 的实例替换为 SHEmailValidationTextField 一样简单。

自定义

要自定义默认的错误消息,请使用 setDefaultErrorMessage: 方法。要为特定错误设置特定消息,请使用 setMessage:forErrorCode: 方法。要自定义拼写建议上显示的文本,请使用 setMessageForSuggestion: 方法。

要自定义出现的弹出窗口的外观和感觉,可以将 fillColortitleColorsuggestionColor 属性设置为您所需的值。

基本语法检查

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

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

获取拼写修正建议

NSError *error = nil;
NSString *suggestion = [[[SHEmailValidator] 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
}

更新 IANA TLD 列表

要获取最新的 IANA TLD,请运行位于根目录中的以下脚本:fetch_iana_list.rb

这将更新位于 SHEmailValidator/DomainData.plist 下的 plist。该脚本需要已安装 httparty 和 plist Ruby 程序包。

ARC

SHEmailValidator 使用 ARC。如果您的项目不支持 ARC,只需在所有 SHEmailValidator 源文件上设置 -fobjc-arc 标志即可。

使用此库的应用程序

本库被用于我们的SpotHero应用程序中。如果您也想将自己应用程序在此列出,请告知我们您正在使用它!

许可证

SHEmailValidator以Apache 2.0许可证发布。