Note that there are some explanatory texts on larger screens.

plurals
  1. PODatabase design for dynamic form field validation
    primarykey
    data
    text
    <p>In my application, I allow users to create a form containing any HTML form field they want (e.g. text input, textarea, select, etc.). I want to give the users the ability to define 0 or more cumulative validation rules for each field (there might be up to 25 different validation rules). How should I model this?</p> <p>Here's a potential solution:</p> <pre><code>============================================================ | Id | FieldId | ValidationRuleType | ValidationRuleDetail | ============================================================ | 1 | 25 | Required | NULL | ------------------------------------------------------------ | 2 | 26 | Minimum Length | 5 | ------------------------------------------------------------ | 3 | 26 | Maximum Length | 12 | ------------------------------------------------------------ ... </code></pre> <p>Using the above design, maybe in most cases, the ValidationRuleType could just be "Regex" (or a value from a lookup table, such as ValidationRuleTypeId = 1 for "Regex"), and use the following for ValidationRuleDetail:</p> <pre><code>// Added bonus of this approach is that users who know regex could define their own patterns .{1,} // Any character, 1 or more times. Use for "Required" .{5,} // Any character, 5 or more times. Use for "Minimum Length = 5" .{,12} // Any character, 12 or less times. Use for "Maximum Length = 12" </code></pre> <p>The problem is that this solution is EAV. That's a bad thing, right?</p> <p>Another potential solution:</p> <pre><code>============================================================= | Id | FieldId | Required | Minimum Length | Maximum Length | ============================================================= | 1 | 25 | TRUE | NULL | NULL | ------------------------------------------------------------- | 2 | 26 | NULL | 5 | 12 | ------------------------------------------------------------- ... </code></pre> <p>Is this better? I'm conflicted on which approach to use. Any guidance I can get is much appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload