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.
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