Validators

Navigation:  Components >

Validators

Previous pageReturn to chapter overviewNext page

Overview

 

Validator components are pieces of validation logic (validation rules) which can be applied to input controls, e.g. TNGRequiredFieldValidator tests if a control is not empty (has some value), TNGRegExpValidator checks if the text in a control matches some regular expression etc. To validate a control, a single validator can be used or several validators combined by a Validation Group component.

 

All the validators are descendants of the TNGCustomValidator class, which in turn descends, along with TNGCustomValidationGroup class, from the TNGValidationEntity class. These abstract classes introduce several properties and methods common for all the validator components which control validation process. These key properties and methods are described below.

 

Note: There's a set of validator components available in the NG ValidatorsPack which introduce properties specific to their validation rules. These rules and properties are described below in the available validators table.

 

Common Key Properties

 

Name

Type

Description

Active

Boolean

If Active is set to False, the validator component does not perform any validation and its Validate function always returns 0 (no errors are found); If Active is set to True (default), the call to Validate function performs actual validation.

ErrorLevel

TNGErrorLevel = Integer

ErrorLevel defines the 'severity' of the error which can be captured by the validator component. It is supposed that greater values correspond to more serious errors. This value is returned by the components's Validate function if the error is detected. This property is used by the Validation Group component to define the order in which validators are applied (they are sorted by ErrorLevel decreasing) and to determine which Error Provider components can be used to indicate errors from the validator component (an error provider is used for the validator if its ErrorLevel lies in range between MinErrorLevel and MaxErrorLevel of the error provider).

ErrorProvider

TNGCustomErrorProvider

The reference to an Error Provider (or Error Provider Group) component which is used for feedback - indicates errors detected by this validator.

ErrorMessage

string

The error message which is supplied to the Error Provider and used for error indication (e.g. as a hint for a hint message, text in a error-indicating control etc.) The text of the message contain placeholders of the form %<Symbol> which are replaced by text corresponding to Symbol. %F is used by all the validators as a placeholder for the text contained in the ValidationMsg property of the validated control. Certain validators introduce other specific placeholders (see below in the Available Validators table).

 

Common Key Methods

 

Name

Parameters

Result type

Description

Validate

Sender: INGValidatedControl; doIndication: Boolean

TNGErrorLevel

In TNGValidationEntity this function is abstract. It is overridden in descendant validator classes to implement actual validation logic. The Sender parameter represents the input control which is to be  validated; the doIndication parameter determines if the error indication using an Error Provider component is to be performed. The actual indication is performed only if an there's an Error Provider assigned to the validator and its [MinErrorLevel.. MaxErrorLevel] range corresponds to the ErrorLevel of the validator.

Sender: INGValidatedControl;

This function calls the Validate(Sender: INGValidatedControl; doIndication: Boolean) function with doIndication = true.

GetMessage

none

string

Returns the actual error message which is to be used for error indication with placeholders replaced by corresponding substitutes. Used internally, but can also be called by the component user.

 

Available Validators

 

Name

Validation rule

Remarks

TNGRequiredFieldValidator

Checks if the validated control is not empty (contains a value).

Space characters are trimmed from both ends of the string value

TNGRegExpValidator

Checks if the value in the validated control matches the specified regular expression (e.g. email address, number in certain format etc.).

The regular expression in specified by the RegExp string property; IgnoreCase boolean property specifies if the regular expression is treated in case-sensitive or case-insensitive way. RegExp sould be a Perl-compatible regular expression (PCRE).

TNGCompareValidator

Compares the value in the validated control with the value in some reference control.

The reference control is specified by the ReferenceControl property and has to support INGValidatedControl interface; the sign of the comparison result for successful validation is specified by the RefSign property and can be rsEqual, rsGreater, rsLess (TNGRefSign enumeration). The type of the values being compared is defined by the ValueType property and can be vtNumber, vtString, vtDate (TNGValueType enumeration). If the ValidateRefControl boolean property is set to True then with each validation of the target control the reference control is also validated which can result in error indication not only for the validated control but for the reference control as well.

TNGRangeValidator

Checks if the value in the control is within the specified range; supports several data types.

The lower and upper range limits are specified by the HighLimit and LowLimit properties respectively. The type of the values representing the range limits is defined by the ValueType property and can be vtNumber, vtString, vtDate (TNGValueType enumeration).

TNGIntRangeValidator

Checks if the integer value in the control is within the specified range.

Integer-typed version of the TNGRangeValidator

TNGFloatRangeValidator

Checks if the floating point value in the control is within the specified range.

Float-typed version of the TNGRangeValidator

TNGStringRangeValidator

Checks if the string value in the control is within the specified range.

String-typed version of the TNGRangeValidator

TNGDateTimeRangeValidator

Checks if the date/time value in the control is within the specified range.

DateTime-typed version of the TNGRangeValidator