VDaemon PHP Library | VDaemon Extension | Table of Contents
The vlvalidator custom tag allows you to validate an associated form input element and display a custom message when validation fails. Each validator performs a specific type of validation. For example, you can validate against a specific value or a range of values. You can even define your own validation criteria. You can control where the message is displayed on the Web page by placing the corresponding vllabel custom tag at the desired location. You can also display a summary of the results from all vlvalidator tags on the page by using the vlsummary custom tag.
Multiple vlvalidator tags can reference the same input element.
Use the validator of required type to make an input element a mandatory field. The input element fails validation if the value it contains does not change from its initial value when validation is performed. This prevents the user from leaving the associated input element unchanged. By default, the initial value is an empty string (""), which indicates that a value must be entered in the input element for it to pass validation.
Extra spaces at the beginning and end of the input value are removed before validation is performed. This prevents a space being entered in the input control from passing validation.
<vlvalidator name="validatorName" type="required" control="inputFieldName" errmsg="errorMessage" minlength="integerValue" maxlength="integerValue" clientvalidate="true"|"false" >
For attribute descriptions see the Attributes section.
Checks if the value of the associated input element can be converted to the specified data type.
<vlvalidator name="validatorName" type="required" control="inputFieldName" errmsg="errorMessage" validtype="type" dateorder="mdy"|"dmy"|"ymd" clientvalidate="true"|"false" >
For attribute descriptions see the Attributes section.
The Range Validator allows you to check whether a user's entry is between a specified upper and lower boundary. You can check ranges within pairs of numbers, strings, and dates. Boundaries are expressed as constants.
<vlvalidator name="validatorName" type="required" control="inputFieldName" errmsg="errorMessage" validtype="type" casesensitive="true"|"false" dateorder="mdy"|"dmy"|"ymd" minvalue="value" maxvalue="value" clientvalidate="true"|"false" >
For attribute descriptions see the Attributes section.
Evaluates the value of an input element against a constant value or the value of another input element to determine whether the two values match the relationship specified by a comparison operator (less than, equal to, greater than, and so on).
<vlvalidator name="validatorName" type="required" control="inputFieldName" errmsg="errorMessage" validtype="type" casesensitive="true"|"false" dateorder="mdy"|"dmy"|"ymd" comparevalue="value" comparecontrol="inputFieldName" operator="e"|"ne"|"g"|"ge"|"l"|"le" clientvalidate="true"|"false" >
For attribute descriptions see the Attributes section.
The RegExp Validator is used to determine whether the value of an input element matches a pattern defined by a regular expression.
<vlvalidator name="validatorName" type="required" control="inputFieldName" errmsg="errorMessage" regexp="pattern" clientregexp="pattern" clientvalidate="true"|"false" >
For attribute descriptions see the Attributes section.
The Email Validator is used to determine whether the value of the associated input element is a properly formatted E-mail address.
<vlvalidator name="validatorName" type="required" control="inputFieldName" errmsg="errorMessage" clientvalidate="true"|"false" >
For attribute descriptions see the Attributes section.
The Custom Validator allows you to create a customized validation logic.
<vlvalidator name="validatorName" type="required" control="inputFieldName" errmsg="errorMessage" function="validationFunctionName" clientfunction="javascriptFunctionName" clientvalidate="true"|"false" >
For attribute descriptions see the Attributes section.
There are several types of vlvalidator tags. Each type has proper set of attributes. But some attributes are common to all types of vlvalidator tags.
Use the Name attribute to set the unique identifier name for the VDaemon vlvalidator custom tag. Name attribute is required for all types of validators except when validator is contained in vlgroup validator.
Use the Type attribute to set the type of validation peformed by validator. Type attribute is required and used by all types of validators. Type attribute receives one of the following values:
- required | Makes the associated input element a required field. |
- checktype | Checks if the value of the associated input element can be converted to the specified data type. |
- range | Checks whether the value of the associated input element is within a specified range of values. |
- compare | Evaluates the value of an input element against a constant value or the value of another input element to determine whether the two values match the relationship specified by a comparison operator (less than, equal to, greater than, and so on). |
- regexp | Evaluates the value of an input element to determine whether it matches a pattern defined by a regular expression. |
Checks if the value of the associated input element is a properly formatted E-mail address. | |
- custom | Evaluates the value of an input element to determine whether it passes customized validation logic. |
Use the Control attribute to specify the input element to validate. This attribute must be set to the name of an input element. If you do not specify a valid input element, an error will occur when the page is rendered. The Control attribute must refer to an input element within the same form as the vlvalidator tag.
All types of vlvalidator tags, except the required, will pass validation if the input element specified by the Control attribute contains no text.
Use the ErrMsg attribute to specify the text to display by the vlsummary custom tag when validation fails.
Specifies the data type of the value being validated. Validation fails if the value of the input element cannot be converted to the specified data type. This attribute valid only for checktype, range and compare vlvalidator tag types. This attribute is set with one of the following values:
- currency | A monetary data type. The value is treated as an signed numeric with or whithout two decimal places. Currency symbol is not allowed. |
- date | A date data type. You should use a format specified by Dateorder attribute. Allowed separators are: "/", "." and "-". |
- float | A floating point number data type. |
- integer | A signed integer data type. |
- string | A string data type. |
The CaseSensitive attribute sets whether comparisons with the input should ignore case. This attribute is valid only for required, checktype, range and compare vlvalidator tag types.
It is used in Checktype, Range and Compare validators when their Validtype attribute is set to "date". Defines valid date format. Possible values are: MDY (default), DMY and YMD.
Use this attribute to specify the minimum length of the associated input element value. By default minlength="1".
Use this attribute to specify the maximum length of the associated input element value. If it is not specified, value can be of any length.
Use the MinValue attribute to specify the minimum value of the validation range. If the value specified by this attribute fails to convert to the data type specified by the ValidType attribute, an error will occur.
Use the MaxValue attribute to specify the maximum value of the validation range. If the value specified by this attribute fails to convert to the data type specified by the ValidType attribute, an error will occur.
Use the CompareValue attribute to specify a constant value to compare with the value entered by the user into the input element being validated. If the constant value specified by this attribute fails to convert to the data type specified by the ValidType attribute, an error will occur.
Use the CompareControl attribute to specify an input element to compare with the input element being validated. If the input element specified by this property is not an element on the page, an error will occur.
Note: Do not set both the CompareControl and CompareValue attributes at the same time. You can either compare the value of an input element to another input element, or to a constant value. If both attributes are set, the CompareValue attribute takes precedence.
Use the Operator property to specify the comparison operation to perform. The following table lists the comparison operations that are possible:
- E | A comparison for equality between the values of the input element being validated and another element, or a constant value. |
- NE | A comparison for inequality between the values of the input element being validated and another element, or a constant value. |
- G | A comparison for greater than between the values of the input element being validated and another element, or a constant value. |
- GE | A comparison for greater than or equal to between the values of the input element being validated and another element, or a constant value. |
- L | A comparison for less than between the values of the input element being validated and another element, or a constant value. |
- LE | A comparison for less than or equal to between the values of the input element being validated and another element, or a constant value. |
Sets the regular expression that determines the pattern used to validate an input element. Perl-Compatible regular expression syntax is used.
Is used in Regexp validator for specifying regular expression pattern which is used in client-side validation. Pattern should comply with Perl-Compatible javascript regular expression syntax (clientregexp="/pattern/[flags]"). If it is not specified, RegExp attribute is used.
Set this attribute to the name of the custom function that performs the validation. Function has the following prototype:
void validationFunctionName($sValue, &$oStatus)
where string parameter $sValue contains value of input element being validated. If
input element is not defined
it contains null.
$oStatus is object of CVDValidatorStatus type (declared in vdaemon.php
file). It has the
following properties:
bValid - defines if corresponding custom validator has passed validation. If not set, considered
as true.
sErrMsg - is used to customize error message.
In custom validator specifies user-defined function name which will be called during client-side validation. If it is not specified, client-side validation for this validator is skipped. Function shold have the following prototype:
void validationFunctionName(oStatus)
where oStatus is javascript object with the following properties:
isvalid - defines is corresponding custom validator passed validation. If not set,
considered as true.
errmsg - is used to customize error message.
value - contains current value of input element being validated. If input element is not defined
it contains null.
Determines if client-side validation for current validator will be performed. Default value is true.