TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: How would you validate data on both back end and front end?

4 pointsby borlumalmost 10 years ago
Dear HN,<p>in most projects you want to do validation of the submitted data both client- and server-side.<p>When using node&#x2F;js the validation is simple, of course, because the validation rules are written once. But, more often than not I don&#x27;t work in JS or use another server side language.<p>My Question: Do you know of any good way to validate objects&#x2F;data structures in a language agnostic way?<p>I have considered something like JSON-schema or some sort of code generation.<p>Any ideas?

5 comments

brudgersalmost 10 years ago
Client side validation is a user interface improvement when it provides convenience. It does not replace server side validation because server side validation ensures application integrity. Of course applications that run in the browser muddy the water a bit, but still whatever hits the server requires scrutiny.
stephenralmost 10 years ago
Do basic validation client side - if you can, rely on html input types and html5 validation attributes. It should be enough to be helpful in most cases without being overly onerous to maintain or hard to match server-side exactly.<p>Put your full detailed validation rules server-side.
lovelearningalmost 10 years ago
In some java web applications, I wrote form validation rules in javascript for client side validation, and reused them server side using java&#x27;s scripting API.
Blackthornalmost 10 years ago
Can you give an example of what you mean by &#x27;validate&#x27;? The word is highly overloaded and has different meaning depending on where the data is being used.
borlumalmost 10 years ago
By validate I mean, rules like:<p>- is &quot;title&quot; set, - when &quot;age&quot; is set &quot;birthday&quot; must not be set. - the cart can have a max of 10 items.