Gdn_Validation::addRule PHP Method

addRule() public method

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.
public addRule ( string $RuleName, string $Rule )
$RuleName string The name of the rule to be added.
$Rule string The rule to be added. These are in the format of "function:FunctionName" or "regex:/regex/". Any function defined here must be included before the rule is enforced or the application will cause a fatal error.
    public function addRule($RuleName, $Rule)
    {
        $this->_Rules[$RuleName] = $Rule;
    }