Reputation: 516
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 [email protected] 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 [email protected]
is true, but [email protected]
is false.
Upvotes: 2
Views: 507
Reputation: 67968
^(?!.*[.][.])[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
Upvotes: 1