Function Updated 23 Oct 2026
isEmail(value)
Validates if a string is an email address, using the .NET MailAddress parser.
The check is lenient: it also accepts a display-name form such as "Test Test" test@test.com and an address without a top-level domain such as x@bug. Add your own check if you need a stricter rule. Values that are not text, and empty text, give false.
Parameters
valueobjectrequiredValue to validate
Returns
True if validates as email.
Example
Mixed HTML (or any text file) with inline JavaScript between hash signs.
#{
// Array with email addresses for testing
const emails = [
"Not an email",
"test@mail.com",
"tes t@mail.com",
"@bug.com",
"x@bug",
"",
null,
"\"Test Test\" <test@test.com>"
];
// Loop through array and test each email
emails.forEach((email, index) => {
const isValid = docly.isEmail(email);
const status = isValid ? "✓ VALID" : "✗ ERROR";
write(`Test ${index + 1}: ${status} - "${email}" => ${isValid}\n`);
});
}#The template above produces this output:
Test 1: ✗ ERROR - "Not an email" => false
Test 2: ✓ VALID - "test@mail.com" => true
Test 3: ✓ VALID - "tes t@mail.com" => true
Test 4: ✗ ERROR - "@bug.com" => false
Test 5: ✓ VALID - "x@bug" => true
Test 6: ✗ ERROR - "" => false
Test 7: ✗ ERROR - "" => false
Test 8: ✓ VALID - ""Test Test" <test@test.com>" => true
Normal JavaScript, running in the browser or on the Docly™ server.
if (docly.isEmail("test@example.com"))
write("Valid email!");
else
write("Invalid email!");The JavaScript above produces this output:
Valid email!