Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need this script to separate email address into two separate alert outputs at the @ symbol. I can get it to output the first half but don't know how to get the second half to work right. Here is what I have so far:

XML
<html>
<body>
<script type="text/javascript">
function convertEmail(inEmail)
{
 var atPosition;
 var stringLength;
 var username;
var domain;
  username = inEmail.indexOf("@");
  stringLength  = inEmail.length;
  domain = inEmail.substr(0,atPosition);
 username = inEmail.substr(atPosition+1, stringLength);
 domain = inEmail.substr(atPosition+1, stringLength);
return username ;
return domain;
}
emailIn  = prompt("Enter username@domain", "Doe@Jane");
alert (convert (inEmail))
alert (convert (inEmail))
</script>
</body>
</html>
Posted

1 solution

hi,

use split function.

C#
var sEmails=inEmail.split("@");
var  use=sEmails[0];
var domain=sEmails[1];   


Hope this can help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900