1.2.2 • Published 11 years ago
email-address v1.2.2
Email address helpers 
Regular expressions ensuring the given input is a valid address.
This module ensure that we use the same approach for validating a given email address across all our services. It was originally lifted from the debitoor-app source/util-folder into its own module.
Overview
Helper functions
Two helper functions, isValid and isMultipleValid, are exposed. isValid is basically a wrapper calling .single.test from the regex section on the input, and isMultipleValid splits a string on commas (,), and verify that every item is a valid email address.
Usage:
var email = require('email-address');
email.isValid('joe@example.com'); // true
email.isValid('foo bar'); // false
email.isMultipleValid('john.doe@example.com,jane.doe@example.com'); // true
email.isMultipleValid('john.doe@example.com,jane.doe@example..com'); // falseRegexes
The following regexes are exposed:
.singlethe string is a valid email address..multiplethe string is a comma seperated list of valid email addresses. Whitespace are allowed between the email addresses..optionalthe string is a valid email address or an empty string.
Usage:
var email = require('email-address');
// input is a vaild email address
email.single.test('joe@example.com'); // true
// input is a comma seperated list of valid email addresses
email.multiple.test('joe@example.com, jane@example.com'); // true
// input is a valid email address, or an empty string
email.optional.test('jane@example.com'); // true
email.optional.test(''); // true