or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

index.mddocs/

Email Validator

Email Validator provides a fast, pretty robust e-mail validator. Only checks form, not function. It implements RFC-compliant length checks for local parts, domain parts, and individual domain segments, while using a comprehensive regex pattern to validate email structure including special characters and proper domain formatting.

Package Information

  • Package Name: email-validator
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install email-validator

Core Imports

const validator = require("email-validator");

For ES6 modules:

import * as EmailValidator from 'email-validator';

Named imports:

const { validate, tester } = require("email-validator");
import { validate, tester } from 'email-validator';

Basic Usage

const validator = require("email-validator");

// Validate email addresses
const isValid1 = validator.validate("test@email.com"); // true
const isValid2 = validator.validate("invalid-email"); // false
const isValid3 = validator.validate("user@domain.co.uk"); // true

// Using named imports
const { validate } = require("email-validator");
const result = validate("example@domain.org"); // true

Capabilities

Email Validation

Validates an email address format using regex pattern and RFC-compliant length checks.

/**
 * Validate an email address.
 * @param {string} email - The email address to validate.
 * @returns {boolean} - Returns true if email format is valid, false otherwise.
 */
function validate(email: string): boolean;

Validation Rules:

  • Local part (before @) maximum 64 characters
  • Domain part (after @) maximum 255 characters
  • Individual domain segments maximum 63 characters each
  • Uses comprehensive regex pattern for format validation
  • Requires exactly one @ symbol
  • Returns false for null/undefined/empty inputs

Usage Examples:

const { validate } = require("email-validator");

// Valid emails
validate("user@example.com"); // true
validate("test.email+tag@domain.co.uk"); // true
validate("user123@sub.domain.org"); // true
validate("a@single-character-in-local.org"); // true

// Invalid emails
validate("@missing-local.org"); // false
validate("missing-at-sign.net"); // false
validate("user@"); // false
validate(""); // false
validate(null); // false

// Length validation
validate("the-local-part-is-invalid-if-it-is-longer-than-sixty-four-characters@sld.net"); // false
validate("user@the-domain-part-is-invalid-if-it-is-longer-than-two-hundred-and-fifty-five-characters.and-this-domain-is-way-too-long.to-be-considered-valid.according-to-rfc-standards.so-it-should-return-false.example.org"); // false

Regex Pattern Access

Access to the underlying regular expression pattern used for email validation.

/**
 * Regular expression pattern used for email format validation
 */
const tester: RegExp;

The regex pattern: /^[-!#$%&'*+\/0-9=?A-Z^_a-z{|}~](.?[-!#$%&'*+/0-9=?A-Z^_a-z{|}~])*@[a-zA-Z0-9](-*\.?[a-zA-Z0-9])*\.[a-zA-Z](-?[a-zA-Z0-9])+$/

Usage Examples:

const { tester } = require("email-validator");

// Direct regex testing
const isMatch = tester.test("user@example.com"); // true

// Custom validation with additional checks
function customValidate(email) {
  if (!email || typeof email !== 'string') return false;
  return tester.test(email) && email.length <= 254; // Additional overall length check
}

Types

For TypeScript users, the package includes type definitions:

/**
 * Validate an email address.
 * @param email - The email address to validate.
 * @returns boolean indicating if email format is valid
 */
export function validate(email: string): boolean;

/**
 * Regular expression pattern used for email validation
 */
export const tester: RegExp;