3 ms·
Agreed. /.+@.+\..+/. Anything "smarter" is almost always overthinking it.
by burke 12y ago
Agreed. /.+@.+\..+/. Anything "smarter" is almost always overthinking it.
- blowski 12y agoDepends on what you're doing. If it's data capture on some kind of competition page, then a more complicated email regex can increase data quality a lot. I have built quite a lot of data capture forms, and while no or limited regex increased number of entries, a more complicated regex combined with checking MX records improved conversion rate, because there were fewer junk entries. I used `\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b` (taken from regular-expressions.info). It has a few false positives and a few false negatives, but overall, it optimises conversion rates, which is what I was being paid for. YMMV.
- masklinn 12y ago> \.[A-Z]{2,4} That should definitely be {2,}: * there are a bunch of gTLD with more than 4 characters: http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains#ICANN-era_generic_top-level_domains http://en.wikipedia.org/wiki/List_of_Internet_top-level_doma... even ignoring geoTLD and brandTLD * ccIDN are all more than 4 characters since the ACE prefix ("xn--" for IDNA) is already 4 characters all on its own
- blowski 12y agoTrue. It probably does need a bit of an update.
- drdaeman 12y agoDot in domain part? That's too restrictive. A few TLDs have MX records. There's no reason to reject an address like, say, "postmaster@ws" - it's a perfectly valid address that could be actually working. And why bother validating anything beyond the fact string's non-empty and there's "@" character? Shoot an email, if they receive it — it's a valid address (no matter how weird it may look), if they don't — well, it's not like something bad happened.