I'm only aware of one case challenging it, and it was a pretty specific context (a 1982 case [1] in which tenured professors challenged their university's ban on taking a second full-time job, which was upheld).
In general though these kinds of restrictions tend to be upheld unless there is a state law against them. There have occasionally been proposals that a robust "right to work" law should generally protect the right to form new contracts selling one's labor to a willing buyer, and void any exclusivity contracts with other parties that would interfere with that right. But in practice all states that I know of with a "right to work" law have adopted a much more limited version of the right, which only voids very specific kinds of exclusivity contracts (relating to employer–union contracts). Some states separately void noncompete agreements under a related principle.
I'm not aware of any state voiding contracts relating to exclusive employment with the employer for the duration of the contract, at least for full-time, salaried employees.
It is called a moonlighting policy, and I suspect they do hold up. Microsoft had that policy in place for decades. They didn't outright ban moonlighting, but you did need to have a formal agreement with your manager. I think they softened it a bit only to encourage employees to build apps for Windows Phone.
I say it probably does hold up because otherwise I am guessing they would have abandoned it. Microsoft has quite a bit of experience with labor dispute litigation. Having billions in cash is like chumming the water for labor law attorneys.
More importantly, you usually end up assigning the rights for your work product to your primary employer. So you can get yourself (or your moonlighting customers) into all sorts of trouble.