Function isEmailAddress
Source: IsEmailAddress.ts
Validates whether a string is a syntactically valid email address. Optionally restricts the allowed length and permitted domains.
Validation rules:
- Length: 6–255 characters (or the configured
maxLength). - No consecutive dots (
..), no dot immediately before@(.@). - Matches the pattern
[email protected]with alphanumeric and limited punctuation. - Domain TLD must be 2–26 alphabetic characters.
Import
ts
import { isEmailAddress } from '@litert/utils-string';Signature
ts
function isEmailAddress(email: string, opts?: IEmailValidationOptions): boolean;Parameters
Parameter
email: stringThe string to validate.
Parameter
opts?: IEmailValidationOptionsOptional validation options. See
IEmailValidationOptions.
Return Value
true if the string is a valid email address (and passes all configured constraints), false otherwise.
Scoped Types
Interface IEmailValidationOptions
Source: IsEmailAddress.ts
ts
import type { IEmailValidationOptions } from '@litert/utils-string';Extra options for the isEmailAddress function.
| Property | Type | Default | Description |
|---|---|---|---|
maxLength | number? | 255 | The maximum allowed length for the email address. If this value exceeds 255, 255 is used instead. |
domains | string[]? | [] | An allowlist of permitted email domains. When provided (and non-empty), only email addresses whose domain is in this list are accepted. Comparison is case-insensitive, but only lowercase domain strings in the list are supported. |
Examples
ts
import { isEmailAddress } from '@litert/utils-string';
isEmailAddress('[email protected]'); // true
isEmailAddress('invalid-email'); // false
isEmailAddress('[email protected]'); // false (TLD too short)
// Domain allowlist
isEmailAddress('[email protected]', { domains: ['example.com'] }); // true
isEmailAddress('[email protected]', { domains: ['example.com'] }); // false
// Custom max length
isEmailAddress('[email protected]', { maxLength: 10 }); // true