Link to home
Start Free TrialLog in
Avatar of maqskywalker
maqskywalker

asked on

In C# check a string variable holding an email address to see if it ends in two types of emails

Hi experts,


I'm using ASP.NET Core 5.0 MVC. So I'm using C# 9


In my HomeController.cs


I'm using the String.EndsWith Method to work with a string


String.EndsWith Method

https://docs.microsoft.com/en-us/dotnet/api/system.string.endswith?view=net-5.0 


I have a string variable holding an email address like this:
This works fine. This if statements checks to make sure the string ends in @yahoo.com


// declare a string variable called strTestEmailAddress

string strTestEmailAddress = "joesmith@yahoo.com";

if (!strTestEmailAddress.ToLower().EndsWith("@yahoo.com"))
{
    // if email address ends in @yahoo.com do stuff inside this if statement

}



Is there a way to use EndsWith to check for 2 types of emails?

Sometimes the variable strTestEmailAddress will hold a @yahoo.com email address and other times it will hold a @microsoft.com email address.


So I need to check if the string the variable strTestEmailAddress ends in @yahoo.com OR @microsoft.com


Anyone know the if statement syntax for that?


if ( )
{
    // if email address ends in @yahoo.com or @microsoft.com do stuff inside this if statement

 }

ASKER CERTIFIED SOLUTION
Avatar of Dr. Klahn
Dr. Klahn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of maqskywalker
maqskywalker

ASKER

thank you for your assistance
thanks