The most common solution is to have a voltage regulator in your device.
Your circuit itself runs on 5V, but the regulator can accept a much higher voltage (say, up to 40VDC) and make 5V from whatever input it gets.
That's what most consumer devices do.
If you want to protect against more extreme mistakes, then a circuit such Andy aka describes can handle much higher voltages.
Regardless of what solution you choose, be aware that they will all fail if the user tries hard enough.
I knew a kid who attached a 120VAC power cable to the barrel plug and connected it to an electronic game just to see what happened. The (expensive at the time) game smoked and burned out - of course.
The folks who designed it didn't include "protect 9VDC input from 120VAC line voltage" in the game because that would cost too much.
Even if it weren't too expensive, you have to draw the line somewhere. 120VAC? Why not 240VAC, or maybe the local distribution transformer shorts and you get 3000VAC? At some point you just have to figure the "protection" is more trouble than it is worth, and the user's device is going to get damaged from misuse.