Better HN
topnewbestaskshowjobs
Log inSign up

_6413

0 karma · joined Sep 25, 2018 (8y ago) · 1 submissions

Submissions

comment 8y ago · link · parent

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