UNPKG

waigo

Version:

Node.js ES6 framework for reactive, data-driven apps and APIs (Koa, RethinkDB)

22 lines (16 loc) 488 B
"use strict"; const validator = require('validator'); const waigo = global.waigo, FieldValidationError = waigo.load('support/forms/field').FieldValidationError; /** * Validator to check whether given string represents an email address. * * @throws Error If not an email address. */ module.exports = function() { return function*(context, field, value) { if (!validator.isEmail('' + value)) { throw new FieldValidationError('Must be an email address'); } } };