Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to extract contents of Email address?

Status
Not open for further replies.
Apr 9, 2007
26
0
0
US
Hi,

With an email address of the organization, the convention is usually same.

for instance, in the org where I work, it is:

firstName.lastName@company.com

I wish to extract the contents before the '@' sign.

How can I do so in Javascript? Any examples which I can look at? I googled for manipulation of email address in Javascript...could not see good examples.

Thanks.
 
You could split it into an array:
Code:
var emailAddress = "firstName.lastName@company.com";
var emailArray = emailAddress.split("@");
alert(emailArray[0]); // firstName.lastName
alert(emailArray[1]); // company.com
var firstName = emailArray[0].split(".")[0];
var lastName = emailArray[0].split(".")[1];
Hope that shows you how it could be done (no error checking in my example of course).

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
One thing to watch out for also is that often there are multiple people with a similar name and the email address has to be offset by either simplifying to an initial on the first name, adding a middle initial or adding a number into the address on the name side. You could test for the presence of a number if that were the case but depending on what you are intending to use the name for once pulled this may not lend you any benefit.

Does your company have an MS Exchange server? If so, you could look into extracting the persons email address and first/last name from the exchange server based on their logon ID. This would require server-side code though.


At my age I still learn something new every day, but I forget two others.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top