GithubHelp home page GithubHelp logo

rodrigopedra / node-isemail Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ranjitc/node-isemail

0.0 2.0 0.0 371 KB

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

License: BSD 3-Clause "New" or "Revised" License

Makefile 0.05% JavaScript 99.95%

node-isemail's Introduction

isemail

Build Status Coverage 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.

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.

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.

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

node-isemail's People

Contributors

skeggse avatar

Watchers

James Cloos avatar Rodrigo Pedra Brum avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.