I am not asking whether to do server-side validation or not.
My question is whether any solution or better practice exist in the software world to address this repetition of code.
I am not asking whether to do server-side validation or not.
My question is whether any solution or better practice exist in the software world to address this repetition of code.
Server-side validation is for security, so users can't bypass client-side validation and send potentially harmful requests.
Client-side validation is for usability, so users can immediately see that for example certain fields are required or need a specific format.
They're not necessarily identical, although in many cases very similar. For example a textfield that's limited to 50 characters on the frontend would probably be limited to 50 characters on the backend as well.
In certain cases it may be possible to avoid doing at least some "double" work, but this usually means that the frontend and the backend are very tightly associated (share the same codebase, frontend linked directly to the backend somehow, possibly using a Rapid Application Development tool). In a normal situation where there are no dependencies between the front-end and the backend (such as a REST API and a Javascript client) there are no generic solutions.