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

Single letter after hyphen in local-part evals false #1

Closed jamesholcomb closed 2 years ago

jamesholcomb commented 2 years ago
const emailRegEx = require('email-regex-safe');
const validator = require('validator');

console.log(validator.isEmail('bill-g@ms.com'));  // true
console.log(emailRegEx().test('email me bill-g@ms.com'));  // false
console.log(emailRegEx().test('email me bill-gates@ms.com'));  // true

Thanks for putting together this repo.

niftylettuce commented 2 years ago

Any chance you could submit a PR to fix with a test?

On Sunday, November 14, 2021, James Holcomb @.***> wrote:

const emailRegEx = require('email-regex-safe');const validator = require('validator'); @.')); // trueconsole.log(emailRegEx().test('email me @.')); // falseconsole.log(emailRegEx().test('email me @.***')); // true

Thanks for putting together this repo.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/niftylettuce/email-regex-safe/issues/1, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAD7XBNAVSYB6TWYUW7RQLDUL7H47ANCNFSM5H7634NA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

jamesholcomb commented 2 years ago

How did you come up with the local-part regex?

https://github.com/niftylettuce/email-regex-safe/blob/0ef7567ec8c5b9db0c6a742920e8d9a21a502c5e/src/index.js#L44

shadowgate15 commented 2 years ago

@jamesholcomb this actually isn't a bug.

You need to add gmail: false to options for emailRegexSafe. The local part is not a valid gmail local part but otherwise it is.