SQL PHP HTML ASP JavaScript articles and free scripts to download
JavaScript String

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

Google+

Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked




HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer