HTML form requirements specification

Posted by Peder on Stack Overflow See other posts from Stack Overflow or by Peder
Published on 2010-03-24T10:24:35Z Indexed on 2010/03/24 10:43 UTC
Read the original article Hit count: 265

Filed under:
|
|
|
|

I am building a framework that will validate forms both client-side (javascript) and server-side based on a form requirements specification written in json.

The purpose is to get rid of logically equivalent code on the server and client to make the code more maintainable, faster to write, and less buggy.

The specification format may look something like:

{ '<field_name>' : ['<validation_function>', 'req', ['<requirement>', <param>], ...], ... }

( the requirement list is ordered so that the user can get most basic error messages first, the 'req' requirement must come first if it exists and means that the field is required)

e.g.)

{
    'name' : ['string', 'req', ['min',6], ['max',150], ['match', /^[\sa-z0-9ÅÄÖåäö&]$/i], ['not_match', /^tmp_/]],
    'email' : ['email', 'req'],
    'email_confirm' : ['same_as', 'email'],
    'password' : ['string', 'req', ['min', 6], ['max', 64], ['match', /^[a-z0-9\!@#\$%^&*_+.]$/i] ],
}

Does anyone know of a similar technology? I think the Rails validation framework solves the problem on the wrong level because I have found that forms often operate on more than one model.

© Stack Overflow or respective owner

Related posts about html

Related posts about forms