4GL Patterns #5 – In-Schema Validation
Thursday, 18 September 2008
There are several ways a database application can enforce that valid data is entered. These can be categorized into: database level, application server level, and client-side.
- (database level) field type: DateTime, Characters, Characters up to a Maximum Length, Nullable, Zero Length string
- (database level) foreign key constraints
- (database level) Databases like MSAccess and SQL Server supply additional field level validation called CHECK constraints.
- (application server level) Application frameworks like Django, CodeIgniter provide additional types: Email, URL. These may provide additional validations such as “ensure url exists”
- (application server level) Classes/Fields may have validation events or named validation rules.
- (client-side) Simpler validation like checking for properly formatted dates, or checking for required fields can be done on the client-side as well, in order to maintain application responsiveness
Example
MS Access developers add a validation rule and a piece of validation text as a constraint against a field. This acts as an annotation. Code generators or forms can read these annotations and raise appropriate error messages if the constraints are not fulfilled.
CodeIgniter uses named validation rules on the server-side (See Rules Reference). Predefined rules include required, matches, min_length, max_length, exact_length, alpha, alpha_numeric, integer, valid_email, valid_emails, valid_ip. There is no reason why these rules can’t be pushed to the client-side as well.
You should follow me on twitter here

No. 1 — September 20th, 2008 at 12:05 am
[...] 4GL Patterns #5 – In-Schema Validation [...]