News for hackers. Stuff that matters.
Re:The secrets of Node's success by jules on Thursday June 09, 2011 @09:04AM (#2636956)
With the right abstractions the code for validating on the client and for validating on the server can be identical. For example take a look at Luna/Lunascript.

This is not easy by just using Node, and it's not necessary that the language you use is Javascript. A better approach IMO is that you have a language X that is nicer than Javascript, and compiles both to server side code and client side Javascript.

For the case of validation here is a hypothetical language (ignore the bad regex):

    <form action="/foo/bar">
      <input type="text" name="email" />
      <%= if not email ~ "[a-z]+@[a-z]+.[a-z]+": invalid("Email is not valid") %>
      <submit>
    </form>
From this code you could generate real time JS validation and server side validation.

There are no comments on this comment yet.