正则表达式用于电子邮件验证 [英] regex for email validation
本文介绍了正则表达式用于电子邮件验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在下面写了正则表达式,用于一个非常简单的电子邮件验证。我打算发送确认链接。
I have written the regex below for a really simple email validation. I plan to send a confirmation link.
/.*@[a-z0-9.-]*/i
然而,我希望从当前状态增强它,因为这样的字符串不会产生所需的结果:
I would, however, like to enhance it from the current state because a string like this does not yield the desired result:
test,my.name + test @ gmail-something.co.uk,test
test ,my.name+test@gmail-something.co.uk, test
测试部分不合需要地包括在比赛中。我尝试了字边界失败。
The "test ," portion is undesirably included in the match. I experimented with word boundaries unsuccessfully.
- 我应该如何修改?
- 即使我保持这个简单,是否有任何有效的电子邮件格式,它会排除?
谢谢!
推荐答案
而不是。尝试匹配除\s(空格)之外的每个字符:
Instead of . try matching every character except \s (whitespace):
/[^\s]*@[a-z0-9.-]*/i
这篇关于正则表达式用于电子邮件验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文