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.
Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle. It only takes a minute to sign up.Sign up to join this community
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.