RegEx - Only one valid email
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]$"
精彩评论