Files
calendar/packages/features/ee/organizations/lib/utils.ts
T
Hariom BalharaandGitHub ee298af4eb fix: update email validation to include pm.me and other email provider domain (#25879)
* fix: update email validation to include pm.me domain and improve error handling in extractDomainFromEmail function

* feat(organizations): add pm.me and additional personal email domains

- Add pm.me (ProtonMail short domain) to personal email providers list
- Add googlemail.com, ymail.com, msn.com, mac.com, and other common personal email domains
- Add Mail.com variants (email.com, post.com, consultant.com, etc.)
- Add protonmail.ch, gmx.de, naver.com, and other regional providers
- Update all three locations: utils.ts, orgCreationUtils.ts, and test file
- Fix ESLint warnings for unnecessary escape characters in regex
2025-12-16 18:45:35 +00:00

69 lines
1.5 KiB
TypeScript

export function extractDomainFromEmail(email: string) {
let out = "";
try {
const match = email.match(/^(?:.*?:\/\/)?.*?([\w-]*(?:\.\w{2,}|\.\w{2,}\.\w{2}))(?:[/?#:]|$)/);
out = (match && match[1]) ?? "";
} catch { /* empty */ }
return out.split(".")[0];
}
/**
* Checks if an email is a company email (not a personal email provider)
*/
export function isCompanyEmail(email: string): boolean {
// A list of popular @domains that are personal email providers
const personalEmailProviders = [
"gmail.com",
"googlemail.com",
"yahoo.com",
"ymail.com",
"rocketmail.com",
"sbcglobal.net",
"att.net",
"outlook.com",
"hotmail.com",
"live.com",
"msn.com",
"outlook.co",
"hotmail.co.uk",
"aol.com",
"icloud.com",
"me.com",
"mac.com",
"mail.com",
"email.com",
"post.com",
"consultant.com",
"myself.com",
"dr.com",
"europe.com",
"engineer.com",
"asia.com",
"usa.com",
"protonmail.com",
"proton.me",
"pm.me",
"protonmail.ch",
"zoho.com",
"yandex.com",
"gmx.com",
"gmx.de",
"fastmail.com",
"inbox.com",
"hushmail.com",
"rediffmail.com",
"tutanota.com",
"mail.ru",
"qq.com",
"163.com",
"naver.com",
"web.de",
"excite.com",
"lycos.com",
];
const emailParts = email.split("@");
if (emailParts.length < 2) return false;
return !personalEmailProviders.includes(emailParts[1].toLowerCase());
}