spamscanner / email-regex-safe

Regular expression matching for email addresses. Maintained, configurable, more accurate, and browser-friendly alternative to email-regex. Works in Node v14+ and browsers. Made for @spamscanner and @forwardemail.
https://forwardemail.net/docs/email-address-regex-javascript-node-js
MIT License
18 stars 8 forks source link

Dot in user-part #2

Closed k4zh closed 2 years ago

k4zh commented 2 years ago

Hi,

Thank you for your lib.

const validator = require('validator');

console.log(validator.isEmail('bob.foo-bar@test.com'));  // true

But using emailRegexSafe({ gmail: false }).exec('bob.foo-bar@test.com'), only foo-bar@test.com matches.

Is that expected behavior?

titanism commented 2 years ago

Looking at the source of validator.isEmail (see https://github.com/validatorjs/validator.js/blob/cfcf9113c69b97477c409909a8729fa8efa0d595/src/lib/isEmail.js#L162-L170), it looks like they split by period to check local parts, and with each split, they test the user pattern. If any parts are not valid, then it rejects it and returns false. We added \\. to our regular expressions and also added a test.

This has been fixed and released in v2.0.0.

https://github.com/spamscanner/email-regex-safe/releases/tag/v2.0.0

Thanks for filing this issue @k4zh