This implementation is not guaranteed to catch all possible errors in an email address. For example, an address like [email protected] will pass validator, even though there is no TLD "nowhere".
public void Validate() { EmailValidator validator = new EmailValidator(); Assert.IsTrue(validator.Validate("*****@*****.**", new ValidationErrors())); Assert.IsTrue(validator.Validate("*****@*****.**", new ValidationErrors())); Assert.IsTrue(validator.Validate("g.m.m@web_ask.com", new ValidationErrors())); Assert.IsFalse(validator.Validate("@eu.s4hc.com", new ValidationErrors())); Assert.IsFalse(validator.Validate("g @s4hc.com", new ValidationErrors())); Assert.IsFalse(validator.Validate("g&@s", new ValidationErrors())); Assert.IsFalse(validator.Validate("goran@s", new ValidationErrors())); Assert.IsFalse(validator.Validate("goran@@", new ValidationErrors())); Assert.IsFalse(validator.Validate("goran@eu s4hc.com", new ValidationErrors())); Assert.IsTrue(validator.Validate(" ", new ValidationErrors())); Assert.IsTrue(validator.Validate("", new ValidationErrors())); Assert.IsTrue(validator.Validate(null, new ValidationErrors())); }