nodesource/isemail

Name: isemail

Owner: NodeSource

Description: validate an email address according to RFCs 5321, 5322, and others

Forked from: hapijs/isemail

Created: 2016-09-20 07:34:12.0

Updated: 2016-09-20 07:34:13.0

Pushed: 2016-09-20 07:38:52.0

Homepage:

Size: 96

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

isemail

Node email address validation library

Build Status[1]

Lead Maintainer: Eli Skeggs

This library is a port of the PHP is_email function by Dominic Sayers.

Install

m install isemail

Test

The tests were pulled from is_email's extensive test suite on October 15, 2013. Many thanks to the contributors! Additional tests have been added to increase code coverage and verify edge-cases.

Run any of the following.

b
m test
ke test

remember to npm install to get the development dependencies!

API

validate(email, [options], [callback])

Determines whether the email is valid or not, for various definitions thereof. Optionally accepts an options object and a callback function. Options may include errorLevel and checkDNS. The callback function will always be called if specified, and the result of the operation supplied as the only parameter to the callback function. If validate() is not asked to check for the existence of the domain (checkDNS), it will also synchronously return the result of the operation.

Use errorLevel to specify the type of result for validate(). Passing a false literal will result in a true or false boolean indicating whether the email address is sufficiently defined for use in sending an email. Passing a true literal will result in a more granular numeric status, with zero being a perfectly valid email address. Passing a number will return 0 if the numeric status is below the errorLevel and the numeric status otherwise.

The tldBlacklist option can be either an object lookup table or an array of invalid top-level domains. If the email address has a top-level domain that is in the whitelist, the email will be marked as invalid.

The tldWhitelist option can be either an object lookup table or an array of valid top-level domains. If the email address has a top-level domain that is not in the whitelist, the email will be marked as invalid.

Only one of tldBlacklist and tldWhitelist will be consulted for TLD validity.

The minDomainAtoms option is an optional positive integer that specifies the minimum number of domain atoms that must be included for the email address to be considered valid. Be careful with the option, as some top-level domains, like io, directly support email addresses. To better handle fringe cases like the io TLD, use the checkDNS parameter, which will only allow email addresses for domains which have an MX record.

Examples
de
r Isemail = require('isemail');
fined
r log = console.log.bind(console, 'result');
fined
email.validate('test@iana.org');

email.validate('test@iana.org', log);
lt true

email.validate('test@iana.org', {checkDNS: true});
fined
email.validate('test@iana.org', {checkDNS: true}, log);
fined
lt true
email.validate('test@iana.org', {errorLevel: true});

email.validate('test@iana.org', {errorLevel: true}, log);
lt 0

email.validate('test@e.com');

email.validate('test@e.com', {checkDNS: true, errorLevel: true}, log);
fined
lt 6
email.validate('test@e.com', {checkDNS: true, errorLevel: 7}, log);
fined
lt 0
email.validate('test@e.com', {checkDNS: true, errorLevel: 6}, log);
fined
lt 6

[1]: if this badge indicates the build is passing, then isemail has 100% code coverage.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.