[英]Regex for email Validation in javascript
I am trying to validate an email using the regular expressions. 我正在尝试使用正则表达式验证电子邮件。 I alomost done but I am failing in one condtion alone which is "a '-' (hyphen) should not be followed by '@'".
我几乎没有做完,但我仅遇到一种情况,即“'-'(连字符)后不能加上'@'”。 I tried in different ways but nothis worked.
我尝试了不同的方法,但是没有用。 Below is the regex I am currently using.
以下是我当前正在使用的正则表达式。
regex = /^(?!.*\.{2})[a-zA-Z0-9][a-zA-Z0-9#$%&\*\+-/=\?\_`|~]*@[a-zA-Z0-9][a-zA-Z0-9-_.]*\.[a-zA-Z]{2,4}$/;
PS : I know the the above regex stops for using two consecutive periods but its my project requirement :( PS:我知道上述正则表达式停止使用两个连续的时期,但它是我的项目要求:(
Please help me in validating for '-' followed by '@' and vice-versa. 请帮助我验证“-”,然后验证“ @”,反之亦然。
Thanks, Yeshwanth 谢谢,Yeshwanth
最简单的方法是在第一次超前之后添加(?!.*-@)
。
Why not just add 为什么不只是添加
[a-zA-Z0-9#$%&\*\+-/=\?\_`|~]*[a-zA-Z0-9#$%&\*\+/=\?\_`|~]@
instead of 代替
[a-zA-Z0-9#$%&\*\+-/=\?\_`|~]*@
? ?
And is it OK to have a +
or, say, a #
right before the dog? 在狗的前面加一个
+
或一个#
可以的吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.