电子邮件地址的正则表达式 [英] Regex for email address

查看:112
本文介绍了电子邮件地址的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以给我看一个用于电子邮件地址的正则表达式示例,以及如何在Objective-C中使用它吗?

Can someone show me a sample RegEx for an email address and how to use in in Objective-C?

寻找适合的内容: name@place.something

推荐答案

功能如下:http://github.com/benofsky/DHValidation

- (BOOL) validateEmail: (NSString *) candidate {
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"; 
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex]; 

    return [emailTest evaluateWithObject:candidate];
}

或添加 http://regexkit.sourceforge.net/RegexKitLite/ 到您的项目,然后像上面一样自己进行regex。

Or add the http://regexkit.sourceforge.net/RegexKitLite/ to your project and do the regex yourself like above.

也可以答复检查电子邮件地址是否真实的问题,不仅可以与正则表达式一起使用,还可以使用以下服务: http://verify-email.org/register/levels.html

Also to reply to the issue of checking if an e-mail address is actually real, not just works with regex you could use some service like: http://verify-email.org/register/levels.html

请注意,此答案未考虑较新的长度TLD,例如.online;包括将最终{2,4}更新为{2,63}的那些人

这篇关于电子邮件地址的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆