电子邮件地址的正则表达式无效 [英] Regex for an email address doesn't work

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

问题描述

  NSPredicate * regexMail = [NSPredicate predicateWithFormat:@SELF MATCHES'。* @。* \ .. *']; 
if([regexMail evaluateWithObject:someMail])
...

但是\。邮件smith @ company被接受后似乎没有工作。此外,我有以下警告:未知转义序列



编辑:



我正在编程iPhone的Objective-C。



谢谢

解决方案

仅使用正则表达式验证电子邮件地址。一个简单的搜索将向您展示许多讨论此事的文章。问题在于DNS的本质:有太多可能的域名(包括非英文和Unicode域),您无法使用正则表达式正确验证它们。别试试



确定电子邮件地址是否有效的唯一正确方法是使用唯一的网址向地址发送邮件,该网址标识与电子邮件相关联的帐户,用户点击。其他任何事情都会使您的最终用户感到烦恼。


I'm trying to check if some email address is correct with the following code :

NSPredicate *regexMail = [NSPredicate predicateWithFormat:@"SELF MATCHES '.*@.*\..*'"];
if([regexMail evaluateWithObject:someMail])
... 

But the "\." doesn't seem to work since the mail "smith@company" is accepted. Besides, I have the following warning : "Unknown escape sequence"

Edit :

I'm programming in Objective-C for iPhone.

Thanks

解决方案

You cannot correctly validate an email address with regular expressions alone. A simple search will show you many articles discussing this. The problem lies with the nature of DNS: there are too many possible domain names (including non-english and Unicode domains), you cannot correctly validate them using a regex. Don't try.

The only correct way to determine if an email address is valid is to send a message to the address with a unique URL that identifies the account associated with the email, for the user to click. Anything else will annoy your end-user.

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

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