Hacker News new | ask | show | jobs
by emodendroket 1137 days ago
Right, you shouldn’t, but that means writing them twice. One of the selling points of backend JavaScript is the same validation code can run on both ends (obviously any validator that needs to check, e.g., uniqueness in a database won’t work).
1 comments

Frontend and backend validation are usually not the same though. You won't be writing the same thing twice, you'll be writing different validations for each.
I think the frontend validations will, most of the time, be a subset of the backend ones, with many shared validation points.
Yes, exactly!

I’ve several times been in the position of writing a new UI for an existing API. You find yourself wanting to validate stuff before the user hits “submit”, because hiding errors until after submitting is terrible UX; and to do that, you find yourself digging into the server code to figure out the validation logic, and duplicating it.

And then years or months later the code gets out of sync, and the client is enforcing all sorts of constraints that aren’t needed on the server any more! Not good.