Files
Gainsight/Scripts/blank_javascript.js

26 lines
755 B
JavaScript
Raw Permalink Normal View History

2025-02-26 16:39:11 -05:00
function extractEmailDomain(email) {
// Check if email is provided and is a string
if (!email || typeof email !== 'string') {
return 'Please provide a valid email address';
}
// Check if email contains @ symbol
if (!email.includes('@')) {
return 'Invalid email format';
}
// Split the email at @ and get the domain part
const domainPart = email.split('@')[1];
// Remove .com or any other extension
const domain = domainPart.split('.')[0];
return domain;
}
// Example usage:
console.log(extractEmailDomain('user@gmail.com')); // Output: gmail
console.log(extractEmailDomain('john.doe@yahoo.com')); // Output: yahoo
console.log(extractEmailDomain('contact@company.org')); // Output: company