public static function ValidateRule($Value, $FieldName, $Rule, $CustomError = FALSE) {
      // Figure out the type of rule.
      if (is_string($Rule)) {
         if (StringBeginsWith($Rule, 'regex:', TRUE)) {
            $RuleName = 'regex';
            $Args = substr($Rule, 6);
         } elseif (StringBeginsWith($Rule, 'function:', TRUE)) {
            $RuleName = substr($Rule, 9);
         } else {
            $RuleName = $Rule;
         }
      } elseif (is_array($Rule)) {
         $RuleName = GetValue('Name', $Rule);
         $Args = GetValue('Args', $Rule);
      }

      if (!isset($Args))
         $Args = NULL;

      if (function_exists($RuleName)) {
         $Result = $RuleName($Value, $Args);
         if ($Result === TRUE)
            return TRUE;
         elseif ($CustomError)
            return $CustomError;
         elseif (is_string($Result))
            return $Result;
         else
            return sprintf(T($RuleName), T($FieldName));
      } else {
         return sprintf('Validation does not exist: %s.', $RuleName);
      }
   }