Show HN: validate.js - lightweight JavaScript form validation library
rickharrison.github.com
rickharrison.github.com
Client-side validation should always be assumed to be disabled completely - view it as merely a convenience for your users. Help them switch dates into a correct format, make sure their userids aren't taken before they finish filling out their forms, that sort of thing.
I think the parent of your comment was talking about using SSJS to re-use validation on both ends of the pipe.
Super easy to deal with on a simple ajax request and it's in place for all requests. If a POST/PUT is done with an ajax request simply return the error message. Otherwise, set the HTTP status code and render the form with the error as the response.
¹http://bassistance.de/jquery-plugins/jquery-plugin-validatio...
Salid - The Simple jQuery Form Validator
http://www.jqueryin.com/projects/salid-the-simple-jquery-for...
The version I use now is tweaked with improvements. I'll gladly share it; I've just been busy and not posting much to the site. If you see problems with the validation methods, they've been fixed over the year in the new version.
The actual field that doesn't validate needs to be highlighted, because otherwise the disconnect between the error and the source makes it difficult to actually identify the source. The only other thing it needs is to position the error message adjacent to the invalid field.
When HTML5 is implemented better these things could be used more effectively. But HTML5 validation as it is now isn't useful until you can style the browser's errors.
It might be a better idea to hold off on the HTML5 stuff and work on polishing up the output :) Unless there's more control over the fancy new features now.
I tried to add something like this to a small validation library I wrote about a year ago. I think that part worked pretty well but otherwise it wasn't very well designed. Another problem I ran into was the lack of support for rules that depended on asynchronous operations.
{
rules: 'regex',
params: {
regex: [/abc/]
}
}
or, {
rules: 'regex:^foo'
}Check my ruby snippet for possible inspiration:
https://gist.github.com/571093 (IBAN, ISBN, ISSN, VATIN and some other numbers used in Poland)
http://vrs.tomelders.com/index.php?title=Main_Page
The hope is that one day, browsers could have a native VRS implementation, and until that day Javascript and serverside scripting could pick up the slack.