In order to validate email address, we are relaying on MailAddress Class. However, this email a@bbb..com address seems to be valid according to MailAddress class.
MSDN states that this are valid email address:
The MailAddress class supports the following mail address formats:
- A simple address format of user@host. If a DisplayName is not set, this is the mail address format generated.
- A standard quoted display name format of "display name" . If a DisplayName is set, this is the format generated.
- Angle brackets are added around the User name, Host name for "display name" user@host if these are not included.
- Quotes are added around the DisplayName for display name , if these are not included.
- Unicode characters are supported in the DisplayName. property.
- A User name with quotes. For example, "user name"@host.
- Consecutive and trailing dots in user names. For example, user...name..@host.
- Bracketed domain literals. For example, .
- Comments. For example, (comment)"display name"(comment)<(comment)user(comment)@(comment)domain(comment)>(comment). Comments are removed before transmission.
Taken from https://msdn.microsoft.com/en-us/library/system.net.mail.mailaddress%28v=vs.110%29.aspx.
Note that 7 bullet is close to this problem, but it says that the consecutive dots can appear in the username not in the domain.
Other resources like http://isemail.info (http://isemail.info/a@bbb..com) states that this is not a valid email address.
What do you think it should be the correct behaviour?. Here is a poc.
//C# Example
var emailAddress = @"a@bbb..com";
Func<string,bool> validEmail = (email)=>
{
try
{
var address = new System.Net.Mail.MailAddress(email);
return true;
}catch (Exception ex)
{
return false;
}
};
Assert.IsTrue(validEmail(emailAddress));
//using NUnit.Framework
//O2Ref:nunit.framework.dll