HNHacker News
TopNewBestAskShowJobs

_6413

0 karma · joined September 25, 2018

submissionscomments
_6413··on Introducing Firefox Monitor, Helping People Take Control After a Data Breach
Your isValidEmail() function is incorrectly and redundantly implemented.

    function isValidEmail(e) {
        const b = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        return b.test((e + "").toLowerCase())
    }
1. The valid email address n@ai (which used to be the real maintained email address of Ian Goldberg) doesn't pass this function. People can put DNS records on TLDs.

2. You're calling toLowerCase() yet the regex is already case-agnostic.

If you're going to attempt email address validation, either go all out[1], or just use isValidEmail=(e)=>~e.indexOf("@")

[1]: http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html