2

I'm trying to make simple email validation by myself. And I need to combine two patterns:

1) @"^[A-Za-z0-9][A-Za-z0-9._-]+[A-Za-z0-9]@[A-Za-z0-9][A-Za-z0-9.-]+\.[A-Za-z0-9.-]+[A-Za-z0-9]$" // allows only xxxx@xxx.xx and dot is not the first or last charachter of local and domain part

2) @"^([^\.]|([^\.])\.[^\.])*$" // there must not be two or more dots in a row.

In other words, I want to add to the first regex a condition that asd.asd@asd.com is true, but asd..asd@asd.com is false.

jaco0646
  • 15,303
  • 7
  • 59
  • 83
cepbuch
  • 486
  • 1
  • 4
  • 10

1 Answers1

1
^(?!.*[.][.])[A-Za-z0-9][A-Za-z0-9._-]+[A-Za-z0-9]@[A-Za-z0-9][A-Za-z0-9.-]+.[A-Za-z0-9.-]+[A-Za-z0-9]$

Just add a lookahead for the same.

See demo.

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

vks
  • 67,027
  • 10
  • 91
  • 124