2 ms·
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 (obvio
by emodendroket 4y 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).
- ZephyrBlu 4y agoFrontend 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.
- emodendroket 4y agoI think the frontend validations will, most of the time, be a subset of the backend ones, with many shared validation points.
- iainmerrick 4y agoYes, 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.