Assuming the US, this is mostly under state law.
In general courts say as long as they do not prevent you from earning a living, they are generally enforceable. Contracts that prohibit working two jobs at once (no moonlighting or hobby game side projects) are generally legal. Contracts that prohibit public appearance for several months at a new job (think news anchors or community management where many customers would follow the individual, executives, and famous names) can be enforceable under some circumstances. Contracts that prohibit working at competitors for a time are rarely enforceable, unless they are for the duration of a severance package or similar so that they are still paid.
Just like NDAs, gag requirements, and severance confidentiality terms, actual enforcement (more than firing someone) usually requires court action, and it is expensive. It is rare for companies to invest the money – probably a few thousand dollars if uncontested and tens of thousands if they fight it out, more for really big fights – but for most general workers the worst that would happen is termination without any parachute. Unemployment benefits often do not apply for termination with cause.
For some side projects, hobby projects, book deals, patents and inventions, and more, you must get written approval or a written document rejecting claims to the project depending on the contract. Without it the company may be able to claim ownership and money from the project.