LMD-Tools Validators Guide


Validators


Overview

 

Validator components are pieces of validation logic (validation rules) which can be applied to input controls, e.g. TLMDRequiredFieldValidator tests if a control is not empty (has some value), TLMDRegExpValidator 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 TLMDCustomValidator class, which in turn descends, along with TLMDCustomValidationGroup class, from the TLMDValidationEntity 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.

 

There's a set of Validator components available in the LMD Validators Pack 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

TLMDErrorLevel = 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

TLMDCustomErrorProvider

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: ILMDValidatedControl; doIndication: boolean

TLMDErrorLevel

In TLMDValidationEntity 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: ILMDValidatedControl;

This function calls the Validate(Sender: ILMDValidatedControl; 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

TLMDRequiredFieldValidator

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

Space characters are trimmed from both ends of the string value

TLMDRegExpValidator

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).

TLMDCompareValidator

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 ILMDValidatedControl interface; the sign of the comparison result for successful validation is specified by the RefSign property and can be rsEqual, rsGreater, rsLess (TLMDRefSign enumeration). The type of the values being compared is defined by the ValueType property and can be vtNumber, vtString, vtDate (TLMDValueType 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

TLMDRangeValidator

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 (TLMDValueType enumeration).

TLMDTypedValidator descendants (somewhat more efficient that all-type ones because of explicitly-typed values used)

TLMDIntRangeValidator

checks if the integer value in the control is within the specified range

integer-typed version of the TLMDRangeValidator

TLMDFloatRangeValidator

checks if the floating point value in the control is within the specified range

float-typed version of the TLMDRangeValidator

TLMDStringRangeValidator

checks if the string value in the control is within the specified range

string-typed version of the TLMDRangeValidator

TLMDDateTimeRangeValidator

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

datetime-typed version of the TLMDRangeValidator