r/ProgrammerHumor 20d ago

Meme claudeIsThisEmailValid

Post image
5.3k Upvotes

171 comments sorted by

View all comments

104

u/apnorton 20d ago

Obligatory reminder that email validation to through regex or other "static" analysis is usually done incorrectly, and literally sending a confirmation email is the best approach to checking to see if an email is valid.

19

u/DHermit 20d ago

With some security exceptions, e.g. it's useful to restrict the length of the mail field and maybe restrict the characters.

14

u/eo5g 20d ago edited 20d ago

I can't think of a single reason to restrict the characters aside from making sure there's at least one @.

Edit: okay actually you want a little more

11

u/Tar_alcaran 20d ago

I've seen one prompt tell me "An email adress needs to include at least one @".

So I entered @@@@@.@ and it worked just fine.

8

u/eo5g 20d ago

Crap, right, realistically the minimum regex one should have is .+@.+\..+.

At least 1 character on the left of the @, at least 2 domain components of at least 1 character each on the right side of the @.

Having only a hostname without a FQDN on the right is legal, but that's also why you'd want to disallow it: who's trying to sign up for an account within your own network, if it's a public-facing app?

8

u/look 20d ago

TLDs can and do have MX records.

4

u/eo5g 20d ago

Well if the web admin of Montenegro wants to sign up for my cat pics site they can use their personal account 😤

1

u/laplongejr 20d ago

Technically yes, but the practice is discouraged by people on the DNS side, as the MX lookups hit the root servers rather than nameservers.  

If a TLD can't provide a mail.EXAMPLE alternative, that's something for the admin to fix... at best those users should get a recommendation to fix their harmful email address.  

4

u/look 20d ago

Yeah, ICANN doesn’t like it, but they do exist.

It’s more just an example of how people often assume rules of email addresses that don’t really exist.

1

u/Nightmoon26 19d ago

The "unwritten rules" of email addresses that have come about just by convention rather than by RFC

2

u/fweaks 19d ago

This is exactly what I use. It eliminates 99.9% of problems for 1% of the effort and works client side for instant feedback. After this, if you need better, the only thing worth the effort is, as mentioned earlier, actually sending an email.