VDaemon PHP Library | VDaemon Extension | Table of Contents

VDaemon Reference
<VLVALIDATOR> Custom Tag

The vlvalidator custom tag allows you validating an associated form input element and displaying 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.

Required Validator

Use the validator of required type to make an input element a mandatory field. The input element fails validation if the length of value it contains does not fall within the range defined by minlength and maxlength. By default, minimum length is 1, maximum length is not specified, that indicates that any value must be entered in the input element to pass validation (field can not be blank).

Extra spaces at the beginning and end of the input value are removed before validation is performed.

Syntax
<vlvalidator
      name="validatorName"
      type="required"
      control="inputFieldName"
      errmsg="errorMessage"
      minlength="integerValue"
      maxlength="integerValue"
      clientvalidate="true"|"false"
      negation="true"|"false"
      setfocus="true"|"false"
>

For attribute descriptions see the Attributes section.

CheckType Validator

Checks if the value of the associated input element can be converted to the specified data type.

Syntax
<vlvalidator
      name="validatorName"
      type="checktype"
      control="inputFieldName"
      errmsg="errorMessage"
      validtype="type"
      groupchar="char"
      decimalchar="char"
      dateorder="mdy"|"dmy"|"ymd"
      timeformat="12"|"24"
      clientvalidate="true"|"false"
      required="true"|"false"
      negation="true"|"false"
      setfocus="true"|"false"
>

For attribute descriptions see the Attributes section.

Range Validator

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.

Syntax
<vlvalidator
      name="validatorName"
      type="range"
      control="inputFieldName"
      errmsg="errorMessage"
      validtype="type"
      casesensitive="true"|"false"
      groupchar="char"
      decimalchar="char"
      dateorder="mdy"|"dmy"|"ymd"
      timeformat="12"|"24"
      minvalue="value"
      maxvalue="value"
      clientvalidate="true"|"false"
      required="true"|"false"
      negation="true"|"false"
      setfocus="true"|"false"
>

For attribute descriptions see the Attributes section.

Compare Validator

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

Syntax
<vlvalidator
      name="validatorName"
      type="compare"
      control="inputFieldName"
      errmsg="errorMessage"
      validtype="type"
      casesensitive="true"|"false"
      groupchar="char"
      decimalchar="char"
      dateorder="mdy"|"dmy"|"ymd"
      timeformat="12"|"24"
      comparevalue="value"
      comparecontrol="inputFieldName"
      operator="e"|"ne"|"g"|"ge"|"l"|"le"
      clientvalidate="true"|"false"
      required="true"|"false"
      negation="true"|"false"
      setfocus="true"|"false"
>

For attribute descriptions see the Attributes section.

RegExp Validator

The RegExp Validator is used to determine whether the value of an input element matches a pattern defined by a regular expression.

Syntax
<vlvalidator
      name="validatorName"
      type="regexp"
      control="inputFieldName"
      errmsg="errorMessage"
      regexp="pattern"
      clientregexp="pattern"
      clientvalidate="true"|"false"
      required="true"|"false"
      negation="true"|"false"
      setfocus="true"|"false"
>

For attribute descriptions see the Attributes section.

Format Validator

The Format Validator is used to determine whether the value of the associated input element is formatted according to predefined format type.

Syntax
<vlvalidator
      name="validatorName"
      type="format"
      format="formatType"
      control="inputFieldName"
      errmsg="errorMessage"
      clientvalidate="true"|"false"
      required="true"|"false"
      negation="true"|"false"
      setfocus="true"|"false"
>

For attribute descriptions see the Attributes section.

Custom Validator

The Custom Validator allows you to create a customized validation logic.

Syntax
<vlvalidator
      name="validatorName"
      type="custom"
      control="inputFieldName"
      errmsg="errorMessage"
      function="validationFunctionName"
      clientfunction="javascriptFunctionName"
      clientvalidate="true"|"false"
      setfocus="true"|"false"
>

For attribute descriptions see the Attributes section.

Attributes

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.

Name Attribute

Use the Name attribute to set the unique identifier name for the VDaemon vlvalidator custom tag.

Type Attribute

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 mandatory 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.
- format Checks if the value of the associated input element is formatted according to predefined format type.
- custom Evaluates the value of an input element to determine whether it passes customized validation logic.
Control Attribute

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.

ErrMsg Attribute

Use the ErrMsg attribute to specify the text to display by the vlsummary custom tag when validation fails.

ValidType Attribute

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 is used only by 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 "-".
- time A time data type. You should use a format specified by TimeFormat attribute.
- datetime A datetime data type. You should use a formats specified by Dateorder and TimeFormat attributes. Allowed separators are: "/", "." and "-" for date and ":" for time.
- float A floating point number data type.
- integer A signed integer data type.
- string A string data type.
GroupChar Attribute

It is used in checktype, range and compare validators when their Validtype attribute is set to "integer", "float" or "currency" . Defines 3 digits grouping symbol. Must be empty value (default) or exactly one char. For example if groupchar="," then 12,234,567 is valid integer.

DecimalChar Attribute

It is used in checktype, range and compare validators when their Validtype attribute is set to "float" or "currency" . Defines decimal symbol. Must be exactly one char. Default value is "." For example if decimalchar="," then 12,2 is valid float.

CaseSensitive Attribute

The CaseSensitive attribute sets whether comparisons with the input should ignore case. This attribute is valid only for checktype, range and compare vlvalidator tag types.

DateOrder Attribute

It is used in checktype, range and compare validators when their Validtype attribute is set to "date" or "datetime" . Defines valid date format. Possible values are: MDY (default), DMY and YMD.

TimeFormat Attribute

It is used in checktype, range and compare validators when their Validtype attribute is set to "time" or "datetime" . Defines valid time format. Possible values are: 12 (default) and 24.

MinLength Attribute

Use this attribute to specify the minimum length of the associated input element value. By default minlength="1".

MaxLength Attribute

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.

MinValue Attribute

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.

MaxValue Attribute

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.

CompareValue Attribute

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.

CompareControl Attribute

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.

Operator Attribute

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.
RegExp Attribute

Sets the regular expression that determines the pattern used to validate an input element. Perl-Compatible regular expression syntax is used.

ClientRegExp Attribute

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.

Format Attribute

Sets the format type used to validate an input element. Can accept one of the following values:

- email Determines whether the value of the associated input element is a properly formatted E-mail address.
- zip_us5 Determines whether the value of the associated input element is a properly formatted US 5 digits zip code.
- zip_us9 Determines whether the value of the associated input element is a properly formatted US 9 digits zip code.
- zip_us Determines whether the value of the associated input element is a properly formatted US 5 or 9 digits zip code.
- zip_canada Determines whether the value of the associated input element is a properly formatted Canada zip code.
- zip_uk Determines whether the value of the associated input element is a properly formatted United Kingdom zip code.
- phone_us Determines whether the value of the associated input element is a properly formatted US phone number.
- ip4 Determines whether the value of the associated input element is a properly formatted IP version 4 address.
Function Attribute

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.

ClientFunction Attribute

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.

ClientValidate Attribute

Determines if client-side validation for current validator will be performed. Default value is true.

Required Attribute

Makes the associated input element a mandatory field. Default value is false.

Negation Attribute

Inverts the result of validation. Acts just like logical "NOT" operator. Default value is false.

SetFocus Attribute

Prevents setting focus to the associated input element if validation fails . Default value is true.