Improve e-mail validity check by requiring surrounding characters

master
Sven Slootweg 4 years ago
parent 29df1a24d4
commit c13c83a7cc

@ -8,11 +8,13 @@ let commonErrors = [
/^.+<[^>]+>$/, // Real Name <email@example.com>
];
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`);
}
}

Loading…
Cancel
Save