Execute a single validation rule and return its result.
public static validateRule ( mixed $Value, string $FieldName, string | array $Rule, string $CustomError = false ) : boolean | string | ||
$Value | mixed | The value to validate. |
$FieldName | string | The name of the field to put into the error result. |
$Rule | string | array | The rule to validate which can be one of the following.
- string: The name of a function used to validate the value.
- 'regex: |
$CustomError | string | A custom error message. |
return | boolean | string | One of the following - TRUE: The value passed validation. - string: The error message associated with the error. |
/** * Validates a rule on the form and adds its result to the errors collection. * * @param string $FieldName The name of the field to validate. * @param string|array $Rule The rule to validate against. * @param string $CustomError A custom error string. * @return bool Whether or not the rule succeeded. * * @see Gdn_Validation::ValidateRule() */ public function validateRule($FieldName, $Rule, $CustomError = '') { $Value = $this->getFormValue($FieldName); $Valid = Gdn_Validation::validateRule($Value, $FieldName, $Rule, $CustomError); if ($Valid === true) { return true; } else { $this->addError('@' . $Valid, $FieldName); return false; } }