正则表达式不允许电子邮件中的点位于错误的位置 [英] Regex to don't allow dots in email at wrong position

查看:162
本文介绍了正则表达式不允许电子邮件中的点位于错误的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须验证公司的电子邮件。正则表达式应该验证,如果它来自公司,可能来自约翰。



我的正则表达式现在看起来像这样:



/ [a-z0-9。] *(john)[a-z0-9。] * @ mycompany\.com /



唯一的问题,它允许点错误的地方。
我看到有效的这封电子邮件:



john@mycompany.com
smith.john@mycompany.com
john.smith@mycompany.com



但我不应该看到有效的:



john。@ mycompany.com
.john @ mycompany.com

解决方案

/ ^([a-z0-9] [a-z0-9。] *)?(john)([a-z0-9。] * [a -z0-9])?@ mycompany\.com $ /



这应该确保前后的字符(john)不要以开始/结束。


I have to validation emails from a company. The regex should validate if it come from the company and could come from John.

My regex looks like this now:

/[a-z0-9.]*(john)[a-z0-9.]*@mycompany\.com/

The only problem, it's allows dots in wrong place. I see valid this emails:

john@mycompany.com smith.john@mycompany.com john.smith@mycompany.com

But i shouldn't see valid these:

john.@mycompany.com .john@mycompany.com

解决方案

/^([a-z0-9][a-z0-9.]*)?(john)([a-z0-9.]*[a-z0-9])?@mycompany\.com$/

This should make sure that characters before/after (john) don't start/end with a . respectively.

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

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