It should not be legal. You exchange your time to produce money for the company, and that's it. You should be able to do whatever you want out of the company hours, and I don't see how that can be a problem. It makes 100% sense from a worker perspective to not have your company have complete control of you. There are plenty of other workers to choose from if you are a company, in case you are dissatisfied with an employee.