CyrefJS
CCyrefJS
فا
Back to documentation
Validation/Since 1.38.0

isEmail

Checks whether a value is a string that matches the utility's email validation rules.

isEmail(value):boolean

Validation rules

The value must be a string. The string is trimmed before validation and must contain exactly one @ character. The local part must be non-empty and cannot start or end with a dot or contain consecutive dots. The local part is restricted to ASCII letters, digits, and the characters .!#$%&'*+/=?^_`{|}~-.

Domain rules

The domain must be non-empty, contain at least one dot, and cannot start or end with a dot or contain consecutive dots. Each domain label must be non-empty, contain only ASCII letters, digits, and hyphens, and cannot start or end with a hyphen.

Type guard

The function is a TypeScript type guard. When it returns true, TypeScript narrows the value from unknown to string.

Parameters

valueunknownrequired

The value to validate as an email address.

Returns

boolean

Returns true when the value is a valid string according to the utility's email validation rules; otherwise returns false.

Examples

01

Valid email

Returns true for a string that satisfies the validation rules.

TypeScript
isEmail("amir@example.com");
// true
02

Invalid email

Returns false when the email structure does not satisfy the validation rules.

TypeScript
isEmail("amir@example");
// false
03

Non-string value

Non-string values are rejected immediately.

TypeScript
isEmail(123);
// false

isEmail(null);
// false
04

Whitespace

Leading and trailing whitespace is removed before validation.

TypeScript
isEmail("  amir@example.com  ");
// true
05

Invalid local part

The local part cannot start or end with a dot or contain consecutive dots.

TypeScript
isEmail(".amir@example.com");
// false

isEmail("amir..test@example.com");
// false
06

Invalid domain

The domain must contain at least one dot, and its labels cannot start or end with a hyphen.

TypeScript
isEmail("amir@example");
// false

isEmail("amir@-example.com");
// false
Built with@cyref/js·Official documentation