Hello, my name is XXXXX XXXXX it is my pleasure to assist you with your question today.
It is entirely legal for an employer to do that, as long as it is correctly drafted. In fact this right is given to them by law - for example section 39 of the Patents Act 1977 provides that an invention belongs to an employer if it was made in the course of the employee's normal or specifically assigned duties; or it was made in the course of the employee's duties and the employee has, because of the nature of the duties and the particular responsibilities arising from them, a special obligation to further the employer's interests.
However, if the work that was created was not made in the course of the employee's specific duties with their employer then the patent would likely still belong to them.
Similarly, if an employee was the author of literary, dramatic, musical, artistic and film works, and these were created in the course of their employment, then their copyright will also belong to the employer by law.