How do I split an email address to catch all caracteres before of @?

Antonio42
Kilo Guru

Team,

I have tried using a script to split an address email by ("@") and get this in 2 slices using length, but it is not working and I am not sure if I am doing it right. I would like to grab only the username (username@domain.com). Could you please help me on this or guide me if there is something already done to achieve this?

 

 

1 ACCEPTED SOLUTION

sachin_namjoshi
Kilo Patron
Kilo Patron

Please use below to split email address

 

var email = "john.doe@email.com";
var name   = email.substring(0, email.lastIndexOf("@"));
var domain = email.substring(email.lastIndexOf("@") +1);

alert( name );   // john.doe
alert( domain ); // email.com

Regards,
Sachin

View solution in original post

3 REPLIES 3

Steve Socha
Tera Guru

I just used this line of code in an Inbound Action.

// Assuming emailAddress is a string like jsmith@company.com
var userID = emailAddress.split('@')[0];

The split function turns a string into an array of strings, so emailAddress.split('@')[0] would fetch everything preceding the @ and emailAddress.split('@')[1] would fetch everything right of the @

sachin_namjoshi
Kilo Patron
Kilo Patron

Please use below to split email address

 

var email = "john.doe@email.com";
var name   = email.substring(0, email.lastIndexOf("@"));
var domain = email.substring(email.lastIndexOf("@") +1);

alert( name );   // john.doe
alert( domain ); // email.com

Regards,
Sachin

thank you so much!