+ Start a Discussion
sudhirn@merunetworks.comsudhirn@merunetworks.com 

Extract only the first name in email

Hi, 

  We have a email field which is in firstname.lastname@domain.com format my requrement is to extract only the firstname from email field. please suggest me how to extract.

I tried below method which is returning firstname.lastname 
 
LEFT( Owner_Email__c,FIND( "@",Owner_Email__c ) - 1  )

Also when returning firstname can we keep the first letter as capital letter using formula please let me now

Thanks
Sudhir
Dheeraj ChawlaDheeraj Chawla
Hello,

Convert the email field into char array then extract the character which are before ( . )dot. then you will get your first name from this method.
sudhirn@merunetworks.comsudhirn@merunetworks.com
Can you show me a sample example 
Tolga SunarTolga Sunar
This should extract the first name and capitalize the first letter.
 
UPPER ( LEFT (Email, 1)) & MID (Email, 2,FIND( ".",Email ) - 2 )

 
Tolga SunarTolga Sunar
Oops, please change the field name with yours.
Keith McRaeKeith McRae
Sudhir,

You were almost there!

Try using:

LEFT(Owner_Email__c, FIND( ".", Owner_Email__c ) - 1 )

This gives you the first name from from the email.

To get the capital letter try this:

UPPER(LEFT((LEFT(Owner_Email__c, FIND(".", Owner_Email__c)-1)), 1))&LOWER(RIGHT((LEFT(Owner_Email__c, FIND(".", Owner_Email__c)-1)), Len((LEFT(Owner_Email__c, FIND(".", Owner_Email__c)-1)))-1))

Keith
sudhirn@merunetworks.comsudhirn@merunetworks.com
Thank you all for your reply code is working as expected I have a another issue in one of the email there are few emails without last name like 

   matt@abc.com if user is having this I need just the name ignorning @abc.com i.e first name 

   How to add this condition to the exisitng formula code. 

Thanks
Sudhir
Tolga SunarTolga Sunar
Here:
IF ( CONTAINS ( UPPER ( LEFT (Owner_Email__c, 1)) & MID (Owner_Email__c, 2,FIND( ".",Owner_Email__c ) - 2  ), "@"), UPPER ( LEFT (Owner_Email__c, 1)) & MID (Owner_Email__c, 2,FIND( "@",Owner_Email__c ) - 2  ), UPPER ( LEFT (Owner_Email__c, 1)) & MID (Owner_Email__c, 2,FIND( ".",Owner_Email__c ) - 2  ))

 
Keith McRaeKeith McRae
Sudir,

I have taken a slightly different approach to Tolga:

The first letter of an email address can’t be “.” as detailed here: https://en.wikipedia.org/wiki/Email_address

So I start with:
UPPER(LEFT(Owner_Email__c, 1))
which will return the uppercase value of the first character, with non-Latin characters being returned as they are.

Then I check to see if the local-part of the email (everything before the “@”), minus the 1st character that we are already dealing with, contains a “.” character.
IF(CONTAINS(MID(Owner_Email__c, 2, FIND("@",Owner_Email__c)-2), "."), TRUE, FALSE)
If the local-part does contain a “.” (i.e. the condition is TRUE) then I take the string starting at character 2 and finishing with the “.” character and force it to lowercase just in case there are uppercase characters hiding in there.
LOWER(MID(Owner_Email__c, 2, FIND(".",Owner_Email__c)-2))
If the local-part does not contain a “.” (i.e. the condition is FALSE) then I take the string starting as character 2 and finishing with the “@” character and force it to lowercase just in case there are uppercase characters hiding in there.
LOWER(MID(Owner_Email__c, 2, FIND("@",Owner_Email__c)-2))
So, the complete formula becomes
UPPER(LEFT(Owner_Email__c, 1))&IF(CONTAINS(MID(Owner_Email__c, 2, FIND("@",Owner_Email__c)-2), "."), LOWER(MID(Owner_Email__c, 2, FIND(".",Owner_Email__c)-2)), LOWER(MID(Owner_Email__c, 2, FIND("@",Owner_Email__c)-2)))
Keith