textconvert
Version:
Public library to convert text into many conventions and formats.
27 lines (26 loc) • 947 B
TypeScript
/**
* Validates if a string is a valid email address according to RFC 5322 standards.
*
* This function performs comprehensive validation including:
* - Basic email structure (local part + @ + domain)
* - Valid characters in local part and domain
* - Domain must contain at least one dot
* - No consecutive dots
* - No trailing dots or hyphens
* - Length limits (local part ≤ 64 chars, domain ≤ 255 chars)
* - Non-ASCII character rejection
*
* @param text - The string to validate as an email address
* @returns boolean indicating if the string is a valid email address
*
* @example
* ```typescript
* isEmail('user@example.com') // true
* isEmail('user.name@example.com') // true
* isEmail('user+tag@example.com') // true
* isEmail('plainaddress') // false
* isEmail('@example.com') // false
* isEmail('user@') // false
* ```
*/
export declare function isEmail(text: string): boolean;