3 ms·
Imagine you need to check if an email address meets RFC822. You can: a) read the 47 page standard and implement every single requirement, one if statement at a
by mrfredward 8y ago
Imagine you need to check if an email address meets RFC822. You can:
a) read the 47 page standard and implement every single requirement, one if statement at a time, and end up writing 10s of thousands of lines of code that are nearly unverifiable.
b) copy that one regex from the standard, put it in a nice function with a comment on where to find the standard, and move on with your life.
Option b will not only save you a week, but also make it much less likely that you screwed up.
- marcosdumay 8y agoWhat are you building? Almost every time you don't have to do a, you also do not need full email validation. Besides, the regex is wrong, like I said on my comment, so now what do you do? But that's a diversion. You can import a library that will do the same just as well as you can import that regex. Both will have comparable levels of gains and problems, but of very different nature.
- evilDagmar 8y agoOf the two, the regexp from the spec should be preferable, because it is exactly what is in the spec. Some other library would be a once-removed version of it and could actually bring flaws of its own.
- horsawlarway 8y agoActually, both A and B are incorrect choices. Option A is a complete waste of time. Option B uses a regex that is no longer standards compliant and will tell users that their entirely valid email address is invalid (this is usually a no-no...). You're skipping entirely over option C: c) Send the user an email asking them to validate their email. You'll notice option C is actually the preferred method of almost every company that needs your email to be valid. Option C also does not use a regex at all.