开发者

RegEx - Only one valid email

开发者 https://www.devze.com 2022-12-13 06:51 出处:网络
I know it\'s my fault and it is not complicated but I cannot find the answer by myself so I beg you to help me build this RegEx.

I know it's my fault and it is not complicated but I cannot find the answer by myself so I beg you to help me build this RegEx.

I'm trying to avoid users to enter more than one email address by line, so I'd like to limit the "@" occurrences to only 1 and also check there are not commas (,)....

Here's a simplified version of the RegEx I'm already using to check the 开发者_如何学编程input....

\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b

How could I introduced a section to check there are not (@,) on the last part ?

Thanks in advance


Instead of using a regex, you could split the string at the @, and count how many elements the output array has.


Try just to add an ^ and one $

^\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b$


This is what I am currently using. A quick test limited it to a single valid email for me.

@"^(?!.*\.\.)[a-zA-Z0-9\w\._%&!'*=?^+-]*@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]*\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号