1.0.0 • Public • Published

Simple Email Validation

A super simple email validator. Rather than maintaining a complicated email regular expression, this module just ensures that the string exists and has an @ with characters before and after.

Just send them an email already

This module also assumes you want to know why an email is not valid. So rather than just returning a true/false it returns true/Error. You can then log and introspect on the error to know why the email is not valid. Get your regular express to do that!


$ npm install --save simple-email-validation


var isEmail = require('simple-email-validation'),
    isError = require('is-error');
var err = isEmail('not an email');
if (isError(err)) {
    throw err; // not an email does not have an @ symbol
if (isEmail('') === true) {
    // No error here, just a valid email
    // Do whatever you wanted to do with the
    // valid email address, like save it in
    // your database

Configurable Messaging

To enable configurable messages and I18N (internationalization) this module allows you to overrrde the error messages. The second paramter is an object containing message strings that are passed to util.format. For example:

var err = isEmail(null, {
    typeError: '%s no es una cadena'
console.log(err.message); // null no es una cadena

Checking Errors

Because this module does not return false it is reccomended that you use is-error to check that the return value is not an instance of Error.

var isError = require('is-error');
var err = isEmail('');
if (isError(err)) {
    throw err; // is missing the user

But you can also check the error manually like this:

var err = isEmail('');
if (err instanceof Error) {
    throw err; // is missing the user

Browser Support

This module should work just fine in all the browsers you care about. Submit an issue if it does not live up to hat expectation, I would love to accept your PR.

Package Sidebar


npm i simple-email-validator

Weekly Downloads






Last publish


  • wesleytodd