I'm curious about this:
In Microsofts Outlook Express (or Outlook, don't remember well, I'm a Mac user), they have something really cool. Generic rules:
You can configure a set of rules to automatically sort or delete your emails, for instance. It's incredible powerful and easy to use.
These rules looked pretty much like this:
"If email in inbox has subject which contains 'foo', or 'bar', or 'foobar' delete it"
I need to code something similar for a powerful form validation system. The developer should simply be able to create rules like this:
rule: [password_1] is_not_equal_with [password_2]
consequence: show_error '2921'
rule: [firstName] has_less_characters_than '2'
consequence: show_error '1211'
rule: [age] is_numeric, is_smaller_than '13', is_greater_than '130'
consequence: show_error '1522'
rule: [gender] is_equal_with 'female'
consequence: show_group [female_questions]
rule: [termsAndConditionsAccepted] is_not_checked
consequence: show_error '482'
rule: [age] is_less_than 21
consequence: hide_group [income_questions]
Well, I have some ideas how this could be done, and I will post them here as answer. But before I reinvent the wheel: Are there any written concepts I can use as foundation to develop a rule-based validation system similar to this? Or if not, do you have any suggestions how this could be done?
In the example above, everything in square brackets is the name of an html form element. Everything in apostrophs '' is a "hard coded" value to compare against.
The defined rules are translated into PHP code AND JavaScript code to do both client- and server side validation.
Features this must be capable of:
- Conditional rules: Something A depends on something B
- Value comparisons: For integers, floats, strings
- Enable some form control logic as well, like in the "[gender] is_equal_with 'female'" example above.
How could this be done? What are the entities I must consider, from a scientific point of view?
I think the theoretical concept of this is platform independent. Although I will implement this in PHP and JavaScript, there's no reason why a C++ dev should not respond ;-) (I'm an Objective-C guy, btw)