Domain name and userid of email address

We can collect userid and domain name part of any email address by using JavaScript string function slice and indexOf. We will use indexOf function to find the location of @ symbol ( or char ) present inside the email address. Using this value we will slice the string starting from left side 0 position to collect the user id part of the email address. Here is the code.
var my_email="useridhere@sitename.com"
var ind=my_email.indexOf("@");
var my_slice=my_email.slice(0,ind);
document.write(my_slice);

Now how to collect the domain part from the email address? We will use the string.length to find out the total length of the string and then collect the part of the string starting from the location of (@ +1) till the end of the string. Here is the code.
var my_email="useridhere@sitename.com"
var ind=my_email.indexOf("@");
var my_slice=my_email.slice((ind+1),my_email.length);
document.write(my_slice);

Using substr function

We will use substr function to get userid and domain part. Here is the code
var my_email="useridhere@sitename.com"
var ind=my_email.indexOf("@");
var my_slice=my_email.substr((ind+1));
document.write(my_slice);
Read how domain name and user id is separated from email address by using PHP
JavaScript String Reference Uppercase to lower case by toLowerCase() method
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Post your comments , suggestion , error , requirements etc here




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer