1763 stories
·
1 follower

There's only ONE way to validate an email address

1 Share

The only thing that you can reliably do to validate an email address is to send it an email. YOU SEND IT AN EMAIL! That’s the only way you can do it. I know what you’re thinking,

“I have the best regular expression for this!”

No, you do not. You think you do, but you don’t. Your regular expression is invalid; it’s not good enough. You know the old adage:

“A developer, when faced with a problem, thought ‘I know. I’ll use regular expressions.’ Now he has two problems.”

That’s what you have - you have two problems. I’ve known this for years, and yet I was still convinced recently to add a regular expression-based email validation server-side;

(First of all, never trust a client, right? You can do it all you want there, but it can bypass all your checks. It’s gotta be server-side.)

I put a regular expression-based email validation and I thought “This one’s pretty good.”

In fact – man, I don’t know what came over me; I was actually even talked into copy-pasting one off of a gist! 😭

It looked pretty good, and it covered most of the bases, and sure enough, last week I got an email from a prospective user saying

“Hey, I’m trying to sign up for Changelog Weekly, but it says my email address isn’t valid, and it obviously is valid, because I’m emailing you with it right now…”

And I thought, “I’m an idiot. Why did I put a regular expression-based email validation on my system?”

So don’t do that. I know you can find one on Stack Overflow… I’ll tell you right now, it’s not good enough. Email addresses are SO complicated. There’s so many valid things…

If you’re going to do it – and I’ll admit that I kept it in there, but I just check that there’s some stuff, and then an @, and then some stuff.

~r/^\S+@\S+\.\S+$/

That’s pretty much what you’re gonna be able to do… And that’s just to basically make sure that you don’t get some junk into your database… 🙅‍♀️

But still, all you’ve gotta do is send them an email, and if they click on it, well that’s a valid email address. If they don’t click on it, then who cares…? That’s a hard-learned lesson!

If you want to validate an email address, send it an email. Problem solved.

Until bots start clicking on emails. Then we’re gonna have a whole new issue… But so far I don’t think there are bots that will

  1. create a fake email address
  2. sign up for your thing, and then
  3. access that email address and click on the link

When we get there, then we’ll have to come up with something else. But until then, just send it an email.


What you’ve just read is an excerpt from JS Party #39. I fixed up the formatting a bit for readability, but these (almost) exact words were spoken by me during the Pro Tips segment of that episode. In addition to tips like this one, we also discuss news & trends, interview awesome guests, teach each other things like we’re 5, and have lots of fun doing it. You should totally come party with us live on Thursdays or subscribe to the produced version! Take a listen and let us know what you think. 💚

Discuss on Changelog News

Read the whole story
emrox
2 days ago
reply
Hamburg, Germany
Share this story
Delete

An Orbit Map of the Solar System

1 Share

This week’s map shows the orbits of more than 18000 asteroids in the solar system. This includes everything we know of that’s over 10km in diameter - about 10000 asteroids - as well as 8000 randomized objects of unknown size. This map shows each asteroid at its exact position on New Years’ Eve 1999.

All of the data for this map is shared by NASA and open to the public. However, the data is stored in several different databases so I had to do a decent amount of data cleaning. I’ve explained all of the steps in detail in my open-source code and tutorial, so I’ll just include a sketch of the process here in this blog post:

One of the most challenging parts of this map was figuring out how to make everything legible. It turns out that things in the solar system are distributed somewhat logarithmically. There are exponentially more things closer to the sun, and exponentially more smaller things than big things. So I used a radial logarithmic scale to include large things, far-away things, and tiny, nearby things on the same map. Logarithmic maps aren’t particularly common, but in this case I figured it was ok since no one would use this map for navigation.

For this map I used the NASA HORIZONS server to generate orbit paths centered around the sun. But HORIZONS can also generate orbits centered around anywhere else. From left to right, these rosettes show the surprisingly beautiful paths of Mercury, Venus, Mars, Jupiter, Saturn, and Uranus as seen from Earth. Venus in particular has been described through history as the Pentagram of Venus or the Rose of Venus.

In a dataset of this size, there were so many exceptions that I designed this map using design “guidelines” rather than rules. For example, at first I wanted to map each asteroid with an orbit tail reaching back 10 years. But many asteroids didn’t have enough data, and the inner asteroids moved so fast that the map was illegible from overlapping lines. So in the end the asteroid tails reach back to the last possible data point, or 10 years, or a quarter of the object’s orbit - whichever is smallest.

The name labels are also fairly arbitrary. I tried to label all the largest and most important asteroids, like the ones we’ve investigated with spacecraft. I also included every named object in the outer solar system because this data is pretty sparse. Since I didn’t have room for all the rest, I picked out my personal favorites, like Moomintroll, O’Keefe, and Sauron. Sadly there was no asteroid named Eleanor, but you can find out if your own name is an asteroid by searching the JPL Small-Body Database Browser.

Some early Python experiments on visualizing orbital paths. In these drafts I used data from the moons of Neptune, Jupiter, and Saturn, because a few dozen moons are much easier to manage than several thousand asteroids. Although I didn’t end up using the code, I still really like the orbit ribbons on the far left (the ribbon thickness shows the orbit movement in the z axis).

One last fun fact about this map - you might notice that Pluto is shown inside Neptune’s orbit. It turns out that about 10% of the time, Pluto is actually closer to the sun than Neptune. On 12/31/99 Pluto is further away, but it appears closer here because Neptune’s orbit tail reaches back in time to a point when it was closer to the sun. (I actually didn’t know about this before the project, so I spent a long time trying to find the bug in the code before finally realizing that the map was working as it should).

Read the whole story
emrox
3 days ago
reply
Hamburg, Germany
Share this story
Delete

Kubernetes failure/horror stories

1 Share

Learn from other people’s fail stories. This is a compiled list of public Kubernetes failure stories. Why?

Kubernetes is a fairly complex system with many moving parts. Its ecosystem is constantly evolving and adding even more layers (service mesh, …) to the mix. Considering this environment, we don’t hear enough real-world horror stories to learn from each other! This compilation of failure stories should make it easier for people dealing with Kubernetes operations (SRE, Ops, platform/infrastructure teams) to learn from others and reduce the unknown unknowns of running Kubernetes in production. For more information, see the blog post.

Discuss on Changelog News

Read the whole story
emrox
3 days ago
reply
Hamburg, Germany
Share this story
Delete

The CSS mindset

1 Share

There’s a lot of CSS love & hate that flows around online, and one of the key reasons it is so polarizing is that it takes a different mental model than most other programming.

Author Max Böck has put together a list of some of the items that go into that mental model:

For most people who write CSS professionally, the mindset just comes naturally after a while. Many developers have that “aha!” moment when things finally start to click. It’s not just about knowing all the technical details, it’s more about a general sense of the ideas behind the language. I tried to list some of these here.

Discuss on Changelog News

Read the whole story
emrox
3 days ago
reply
Hamburg, Germany
Share this story
Delete

Making tables responsive with minimal CSS

1 Share

There’s still a use case for tables!! No seriously, there is. If you’d like to learn how to optimize table elements for mobile using minimal CSS, read on…

My recent article, Write HTML Like It’s 1999, received far more attention than I ever expected on HackerNews. With this attention came a few comments mentioning how table elements don’t play nice with mobile devices or that it’s not possible to have a useable layout on smaller screens. This simply isn’t true.

Discuss on Changelog News

Read the whole story
emrox
5 days ago
reply
Hamburg, Germany
Share this story
Delete

Micro frontends

1 Share

What’s the front-end equivalent of a micro-services architecture? A micro-frontends architecture of course. This approach makes a ton of sense, though in my opinion you will definitely want to have an internal components library and some cross-frontend coordination so your UI doesn’t degrade into a series of disconnected, disjointed experiences.

It’s hard to argue against the benefits stated by author Cam Jackson:

Micro frontends are all about slicing up big and scary things into smaller, more manageable pieces, and then being explicit about the dependencies between them. Our technology choices, our codebases, our teams, and our release processes should all be able to operate and evolve independently of each other, without excessive coordination.

Discuss on Changelog News

Read the whole story
emrox
5 days ago
reply
Hamburg, Germany
Share this story
Delete
Next Page of Stories