Wednesday, 10 March 2021

MVC - C# - Check if valid email address

 Watch this example on YouTube


 

       public ActionResult Index()
        {
            var b1 = IsValidEmailAddress("bob@boc.com");
            var b2 = IsValidEmailAddress("Bob@bob@bob");
            return View();
        }

        private bool IsValidEmailAddress(string email)
        {
            try
            {
                var addr = new System.Net.Mail.MailAddress(email);
                return addr.Address == email;
            }
            catch
            {
                return false;
            }
        }

No comments:

Post a Comment