If $RuleName already
exists, this method will overwrite the existing rule. There are some
special cases:
1. If the $Rule begins with "function:", when the rule is evaluated
on a field, it will strip the "function:" from the $Rule and execute
the remaining string name as a function with the field value passed as
the first parameter and the related field properties as the second
parameter. ie. "function:MySpecialValidation" will evaluate as
MySpecialValidation($FieldValue, $FieldProperties). Any function defined
in this way is expected to return boolean TRUE or FALSE.
2. If $Rule begins with "regex:", when the rule is evaluated on a
field, it will strip the "regex:" from $Rule and use the remaining
string as a regular expression rule. If a match between the regex rule
and the field value is made, it will validate as TRUE.
3. Predefined $RuleNames are:
RuleName Rule
========================================================================
Required Will not accept a null or empty value.
Email Will validate against an email regex.
Date Will only accept valid date values in a variety of formats.
Integer Will only accept an integer.
Boolean Will only accept 1 or 0.
Decimal Will only accept a decimal.
Time Will only accept a time in HH:MM:SS or HH:MM format.
Timestamp Will only accept a valid timestamp.
Length Will not accept a value longer than $Schema[$Field]->Length.
Enum Will only accept one of the values in the $Schema[$Field]->Enum array.