- have a specific reason about why you can't work for the new company - you can't just "non-compete" working for another company in an industry, it has to be that you had access to specific know-how that your old employer wants to keep secret from your new employer.
- have the non-compete time-limited, according to how long the know-how is relevant for.
- offer financial compensation (apparently normally the difference between the salary they would have got if there was no non-compete, and the one they did end up getting at another company)
My understanding is that it sometimes happens for people higher-up in the org-chart, and doesn't really happen so much at the individual contributor level. (I'd be really interested to hear other interpretations, anecdotes or case law though!)