They are not illegal, and even if there is a grey area good luck defending.
I worked at a hedge fund in NYC. I gave my 2 week notice. HR said that the employee contract that I signed when I joined stated a minimum of a 4 month notice period. This would have completely killed my next job which I already accepted.
I should have known this was in the employee agreement, but I didn't know they they would threaten lawyers on me if I didn't stay 3 months.