diff --git a/src/lib/isEmail.js b/src/lib/isEmail.js index 12938765e..9d89f8db3 100644 --- a/src/lib/isEmail.js +++ b/src/lib/isEmail.js @@ -162,6 +162,10 @@ export default function isEmail(str, options) { } } + if (options.blacklisted_chars) { + if (user.search(new RegExp(`[${options.blacklisted_chars}]+`, 'g')) !== -1) return false; + } + if (user[0] === '"') { user = user.slice(1, user.length - 1); return options.allow_utf8_local_part ? @@ -178,9 +182,6 @@ export default function isEmail(str, options) { return false; } } - if (options.blacklisted_chars) { - if (user.search(new RegExp(`[${options.blacklisted_chars}]+`, 'g')) !== -1) return false; - } return true; } diff --git a/test/validators.test.js b/test/validators.test.js index 06abe81f5..8037acf37 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -265,12 +265,15 @@ describe('Validators', () => { it('should not validate email addresses with blacklisted chars in the name', () => { test({ validator: 'isEmail', - args: [{ blacklisted_chars: 'abc' }], + args: [{ blacklisted_chars: 'abc"' }], valid: [ 'emil@gmail.com', ], invalid: [ 'email@gmail.com', + '"foobr"@example.com', + '" foo m端ller "@example.com', + '"foo\@br"@example.com', ], }); });