From 47e545a8d04508b460a63a9c47375600dc089829 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Mon, 22 Jun 2020 01:43:57 +0200 Subject: [PATCH] Catch some common e-mail address formatting errors --- index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 308cb33..aa67d29 100644 --- a/index.js +++ b/index.js @@ -3,11 +3,16 @@ const ValidationError = require("@validatem/error"); const isString = require("@validatem/is-string"); +let commonErrors = [ + /^mailto:.+$/, // mailto:email@example.com + /^.+<[^>]+>$/, // Real Name +]; + module.exports = [ isString, function isEmailAddress(value) { - // TODO: Include explanation in README as to how this really *is* the correct check in practice, and that any further validation should be done by actually trying to send an e-mail - if (!value.includes("@")) { + // TODO: Include explanation in README as to how checking for the presence of '@' really *is* the correct check in practice, and that any further validation should be done by actually trying to send an e-mail + if (!value.includes("@") || commonErrors.some((errorRegex) => errorRegex.test(value))) { throw new ValidationError(`Must be an e-mail address`); } }