Comment

Comment by madamelic

Here's how to make sure you parse emails, addresses, names, anything user entered: use the info to verify.

Don't write a regex, don't try to check if _you_ think it is valid. If you need it to be valid, (e)mail them something at that address and get a verification code back.

The amount of times I've been told 1/2 addresses aren't valid (technically, in the US, an address can be any fraction [0]), any address over 30 characters, domains that have tlds longer than 3 characters, domains that have tlds shorter than 3 characters, domains that aren't gmail.com, on and on and on.

Just stop. Stop trying to fit user-entered content into your tiny conception of what is "valid". Your user knows better than you and there is zero chance you'll write or should write a mega regex to determine validity.

[0]: https://pe.usps.com/text/pub28/28ape_004.htm

parent madamelic 4 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton