-3

I searched a lot for a regex pattern which is convenient for me. I couldn't find any.

Here is my conditions,

1. email should not contain any space or special characters(excep @ and .)
2. email should not start with dot(.) or should not end with .(before @ symbot)
3. two dots should not come near.
4. @ symbol should not repeat.

Here some valid and invalid email IDS,

[email protected] -- valid
[email protected] -- invalid(dot and @ should not come closer)
[email protected] --invlid(two dots should not come closer)
firstname#[email protected] -- invalid(should not contain any special characters appart @ and .)
[email protected] -- valid
first [email protected] -- invalie( should not allow any spaces)
[email protected] --invalid(should not start with .)

I found lot of regex pattern for email. but didn't satisfy my conditions

Thanks in advance,

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Sandeep Sudhakaran
  • 1,072
  • 2
  • 9
  • 22
  • 1
    What about writting your own pattern ? – Cid Feb 18 '20 at 13:55
  • For something like this, you'd get much better results if you simply put your question title into Google instead of Stackoverflow. There are hundreds of regexes out there for email addresses. They're not hard to find. Many frameworks and libraries come with one built in. However, you should double-check what is actually valid, because some of your "invalid" criteria are actually valid in email addresses, and you will find people who are using them. – Spudley Feb 18 '20 at 14:03
  • Please, have a look at these sites: [TLD list](https://www.iana.org/domains/root/db); [valid/invalid addresses](https://en.wikipedia.org/wiki/Email_address#Examples); [regex for RFC822 email address](http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html) – Toto Feb 18 '20 at 16:07
  • https://stackoverflow.com/q/201323/372239 – Toto Feb 18 '20 at 16:08

1 Answers1

2

This would work:

^[a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)*@[a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)*$

https://regex101.com/r/nen2SZ/1

MonkeyZeus
  • 20,375
  • 4
  • 36
  • 77