Dear HN,<p>in most projects you want to do validation of the submitted data both client- and server-side.<p>When using node/js the validation is simple, of course, because the validation rules are written once. But, more often than not I don't work in JS or use another server side language.<p>My Question: Do you know of any good way to validate objects/data structures in a language agnostic way?<p>I have considered something like JSON-schema or some sort of code generation.<p>Any ideas?
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.
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.
In some java web applications, I wrote form validation rules in javascript for client side validation, and reused them server side using java's scripting API.
Can you give an example of what you mean by 'validate'? The word is highly overloaded and has different meaning depending on where the data is being used.
By validate I mean, rules like:<p>- is "title" set,
- when "age" is set "birthday" must not be set.
- the cart can have a max of 10 items.