Spliting Domain out from email address.

Hello,

I have the following email addresses:

michael.help@imlost.com
sahar.cool@insurance.com


I need to get the domain (ie. insurance.com) split off the right side because I need to write an if statement after this looking something like the following.

For example....

if(domain == null) ||(domain == "insurance.com")
{
"Employee"
}
else
{
"Other"
}
Michael FranzCFOAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Radek BaranowskiFull-stack Java DeveloperCommented:
String s="some.email@somedomain.com";
int indexOfAt= s.indexOf('@');
String domain= s.substring(indexOfAt+1);
if(domain == null) ||(domain == "somedomain.com")
{
"Employee"
}
else
{
"Other"
}

Open in new window

0
Rainer JeschorCommented:
Hi,
alternative way:
var testaddress = "john@doe.com";
var domain = testaddress.split("@")[1];

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Michael FranzCFOAuthor Commented:
I'm getting an error....I cut the IF off for the time being...


String s="some.email@somedomain.com";
int indexOfAt= s.indexOf('@');
String domain= s.substring(indexOfAt+1);

missing; before statement, line 28: String s=
0
Michael FranzCFOAuthor Commented:
AWESOME!!!! Yea thank you. Easy and it works!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.