static void Main(string[] args) { EmailValidator ev = new EmailValidator(); Console.WriteLine(ev.ValidateEmail("@gmail.com")); Console.WriteLine(ev.ValidateEmail("hello.gmail@com")); Console.WriteLine(ev.ValidateEmail("gmail")); Console.WriteLine(ev.ValidateEmail("hello@gmail")); Console.WriteLine(ev.ValidateEmail("*****@*****.**")); Console.ReadKey(); }
/// <summary> /// Validates the value. /// </summary> /// <remarks> /// Checks whether or not the email address provided is syntactically correct. /// </remarks> /// <param name="value">The value to validate.</param> /// <param name="validationContext">The validation context.</param> /// <returns>THe validation result.</returns> protected override ValidationResult IsValid(object value, ValidationContext validationContext) { var memberNames = new string[] { validationContext.MemberName }; if (value == null) { return(new ValidationResult("Email can't be null", memberNames)); } if (EmailValidator.Validate((string)value, AllowTopLevelDomains, AllowInternational)) { return(ValidationResult.Success); } return(new ValidationResult("Email invalid", memberNames)); }