From c13c83a7ccafa0e027222693fe311e8a4bd5a388 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Mon, 22 Jun 2020 02:33:15 +0200 Subject: [PATCH] Improve e-mail validity check by requiring surrounding characters --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index aa67d29..f0c77f4 100644 --- a/index.js +++ b/index.js @@ -8,11 +8,13 @@ let commonErrors = [ /^.+<[^>]+>$/, // Real Name ]; +let validEmail = /.@./; // Contains an @, and is preceded and succeeded by at least one character + module.exports = [ isString, function isEmailAddress(value) { // 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))) { + if (!validEmail.test(value) || commonErrors.some((errorRegex) => errorRegex.test(value))) { throw new ValidationError(`Must be an e-mail address`); } }