1.38.0isEmail
Checks whether a value is a string that matches the utility's email validation rules.
isEmail(value):booleanValidation 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
valueunknownrequiredThe value to validate as an email address.
Returns
booleanReturns true when the value is a valid string according to the utility's email validation rules; otherwise returns false.
Examples
Valid email
Returns true for a string that satisfies the validation rules.
isEmail("amir@example.com");
// trueInvalid email
Returns false when the email structure does not satisfy the validation rules.
isEmail("amir@example");
// falseNon-string value
Non-string values are rejected immediately.
isEmail(123);
// false
isEmail(null);
// falseWhitespace
Leading and trailing whitespace is removed before validation.
isEmail(" amir@example.com ");
// trueInvalid local part
The local part cannot start or end with a dot or contain consecutive dots.
isEmail(".amir@example.com");
// false
isEmail("amir..test@example.com");
// falseInvalid domain
The domain must contain at least one dot, and its labels cannot start or end with a hyphen.
isEmail("amir@example");
// false
isEmail("amir@-example.com");
// false