31 lines
642 B
TypeScript
31 lines
642 B
TypeScript
|
|
/**
|
||
|
|
* Toolkit - Email Validation
|
||
|
|
*
|
||
|
|
* Email validation utilities.
|
||
|
|
*/
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Validate email address format
|
||
|
|
*/
|
||
|
|
export function isValidEmail(email: string): boolean {
|
||
|
|
// RFC 5322 simplified regex for email validation
|
||
|
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||
|
|
return emailRegex.test(email);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Extract domain from email address
|
||
|
|
*/
|
||
|
|
export function getEmailDomain(email: string): string | null {
|
||
|
|
const match = email.match(/@(.+)$/);
|
||
|
|
return match ? match[1] : null;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Normalize email address (lowercase, trim)
|
||
|
|
*/
|
||
|
|
export function normalizeEmail(email: string): string {
|
||
|
|
return email.trim().toLowerCase();
|
||
|
|
}
|
||
|
|
|