代码库> 文字视图> SHEmailValidator——电子邮件语法检测以及修改建议
SHEmailValidator——电子邮件语法检测以及修改建议
关注
上传者:ccsupport 分类:文字视图(Textview)
查看次数:3600 下载次数:165
上传时间:2013-11-18 大小:253 B
SHEmailValidator是一个iOS库,它会提供最基本的电子邮件语法检查,然后给出可能的修改建议(比如说,test@gamil.con会被修改成test@gmail.com)。
  

基本的语法检测




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
}



收藏
我来说两句
发表评论
您还没有登录!请登录注册
所有评论(0
本周热门下载
综合评论
提示
sina weixin mail 回到顶部