by technomancy · 15y ago · 0 comments
Validation on the client is primarily a user experience concern,
where you focus on bringing attention to problems with a form, and
helping the user resolve those problems.
Once the form is submitted, if you’ve done thorough client-side
validation you can also avoid friendly server-side validation. Of
course all your client-side validation could be avoided through a
malicious client, but you don’t need to give a friendly error
message in that case, you can simply bail out with a simple 400 Bad
Request error.
At that point there’s not much in common between these two kinds of
validation — the client is all user experience, and the server is all
data integrity.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.