

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

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?
======
brudgers
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.

------
stephenr
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.

Put your full detailed validation rules server-side.

------
lovelearning
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.

------
Blackthorn
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.

------
borlum
By validate I mean, rules like:

\- is "title" set, \- when "age" is set "birthday" must not be set. \- the
cart can have a max of 10 items.

