How to extract domain name from email address

This tutorial shows you on how to extract the domain name from an email address by using PHP, Java, VB .NET, C# and Python programming language. The below sample code is useful when you need to extract the domain name to be supplied into FraudLabs Pro REST API (for email_domain field). You may visit the screen order API page to learn more.

Extract Domain in PHP

$email = '';
$domain = substr($email, strpos($email, '@') + 1);


Extract Domain in Java

String email = "";
String domain = email .substring(email .indexOf("@") + 1);


Extract Domain in VB.NET

Dim email As String = ""
Dim startIndex As Integer = email.IndexOf("@")
Dim endIndex As Integer = email.IndexOf(".", startIndex)

Dim domain As String = email.SubString(startIndex + 1, endIndex)


Extract Domain in C#

string email = "";
int indexOfAt = email.IndexOf('@');
string domain = email.Substring(indexOfAt + 1);


Extract Domain in Python

email = ''
domain = email.split('@')[1]



Ready to start with FraudLabs Pro?

Get Micro plan for free, you can quickly explore and integrate with our fraud prevention solution in minutes.


Was this article helpful?

Related Articles