Skip to content

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

License

Notifications You must be signed in to change notification settings

ranjitc/node-isemail

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

isemail

Build Status

This first version of isemail is a port of the PHP is_email function by Dominic Sayers.

Future versions will improve upon the current version, optimizing it for efficient usage and DRYing the code.

Install

$ npm install isemail

Test

The tests were pulled from is_email's extensive test suite on October 15, 2013. Many thanks to the contributors!

Run any of the following.

$ mocha
$ npm test
$ make test

remember to npm install!

API

isEmail(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 isEmail 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 isEmail. 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.

Examples

$ node
> var isEmail = require('isemail');
undefined
> var log = console.log.bind(console, 'result');
undefined
> isEmail('[email protected]');
true
> isEmail('[email protected]', log);
result true
true
> isEmail('[email protected]', {checkDNS: true});
undefined
> isEmail('[email protected]', {checkDNS: true}, log);
undefined
result true
> isEmail('[email protected]', {errorLevel: true});
0
> isEmail('[email protected]', {errorLevel: true}, log);
result 0
0
> isEmail('[email protected]');
true
> isEmail('[email protected]', {checkDNS: true, errorLevel: true}, log);
undefined
result 6
> isEmail('[email protected]', {checkDNS: true, errorLevel: 7}, log);
undefined
result 0
> isEmail('[email protected]', {checkDNS: true, errorLevel: 6}, log);
undefined
result 6

TODO

Add tests for library usage, not just functionality comparisons.

License

BSD License

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published