0

I've the following email pattern:

(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)

Now I have two questions:

  1. Additionally I don't want to allow double dashes e.g.:

    not allowed: john--doe@x--x.c--om

  2. What do you think about the pattern, could it be simplified or does it have some mistakes or uncovered strings?

Martijn Pieters
  • 963,270
  • 265
  • 3,804
  • 3,187
vP3nguin
  • 320
  • 6
  • 18

1 Answers1

2

You can use this regex: (?!.*?--)(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$). I added a negative lookahead that will stop the match if followed by .*--, if it contains --

If you want to use this for a website then you should use another regex as suggested in a comment to match email adresses more strictly, or use available functions in language.

Nicolas
  • 5,917
  • 3
  • 28
  • 65