check-email-js
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

check-email-js

A simple and customizable module that validates email addresses with an optional domain restriction.

Installation

Using npm: $ npm install check-email-js

Using yarn: $ yarn add check-email-js

Usage

Importing

import { checkEmail } from 'check-email-js';

Function Signature

function checkEmail(email: string, options?: CheckEmailOptions): ValidationResult;

Options

The function accepts an optional object with the following options:

Property Type Default Description
domains string or string[] null Domain restrictions for email validation.
max number 3 An optional number representing the maximum length of the top-level domain (TLD). If not provided, the default maximum length is 3.

Return

The function returns an object with the following properties:

Property Type Description
valid boolean Indicates if email is valid or not.
error string or null Error message for invalid email or domain. Returns null if email is valid or if error message is not applicable.

Example Usage

// Standard validation
const result = checkEmail('test@example.com');
console.log(result.valid); // Output: true

// With domain restriction
const result = checkEmail('test@example.com', { domains: 'example.com' });
console.log(result.valid); // Output: true

// With multiple domain restrictions
const result = checkEmail('test@example.com', { domains: ['sample.com', 'example.com', 'test.com'] });
console.log(result.valid); // Output: true

// With custom domain extension max length
const result = checkEmail('test@example.info', { max: 4 });
console.log(result.valid); // Output: true

License

This package is open-sourced software licensed under the MIT license.

Package Sidebar

Install

npm i check-email-js

Weekly Downloads

4

Version

1.0.2

License

MIT

Unpacked Size

18.8 kB

Total Files

7

Last publish

Collaborators

  • kenlabso