If this was not legal, we would all be bound to the same employer for life. This could be extrapolated to virtually any employee. Have you assembled burgers for McDonald's before? If so, you can't work at Burger King, because they also make burgers and you have proprietary knowledge of McDonald's burgers.
I have spoken with numerous individuals who added support for specification X to one vendor's product, then did the same at the next job, so on and so forth. One individual had implemented the same specification for 3 different companies, all competitors, in just a few years. When you consider the breadth and depth of some specifications, the code doubtlessly is similar in form and obviously identical in function.