It should be legal. I dont see the problem with having terms like this. There are plenty of other companies to choose from if you are a developer. From a company perspective it makes 100% sense to have terms that restricts when a developer is allowed to work on a project.