SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Oct 2010
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need to split email address and have two alert outputs

    I need to use string split to get two outputs for an email address, one output the user name and the second to be the domain name, for example xxxxx@xxxx.com needs to be seperated at the @ symbol so one output would be the xxxx and the second would be xxxx.com. Here is what I got so far, the problem I have is I can't figure out how to get the second output right.



    <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>

  2. #2
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you'll find it easier and with much less code if you use split()


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •