Metadata Validator element
The goal of the Validator element is to ensure that the user provides the necessary, properly formatted information to complete an operation successfully.
The validator can only be used in combination with other fields:
- Metadata Checkbox field
- Metadata Input field
- Metadata Select field
- Metadata Suggestbox field
- Metadata TextArea field
Validator element attributes
Section titled “Validator element attributes”| Attribute | Description | Required |
|---|---|---|
| type | The validator type. See the list of available validators below. | true |
| parameter | An optional value passed to the validator. For length validators (maxlen, minlen), specifies the limit. For comparison validators (lt, gt, min, max), specifies the threshold. For regexp, specifies the regular expression pattern. For plugin, not used. |
false |
Available validators:
| name | Description |
|---|---|
| req | Required value. |
| alpha | Alphabetic value. |
| alphanum | Alphanumeric value. |
| dec | Decimal value. |
| num | Numeric value. |
| Email value. | |
| url | URL value. |
| maxlen | Maximum allowed length. |
| minlen | Minimum required length. |
| lt | Less than. |
| gt | Greater than. |
| min | Minimum value. |
| max | Maximum value. |
| regexp | Regular expression. |
| plugin | Create your own form validator. More information at Creating your own Form Validator plugin. |
- Parent:
Basic example
Section titled “Basic example”- Value required: “req”.
- The value must be a decimal: “dec”.
- The maximum length of the decimal value is six digits: “maxlen”.
<input label="Decimal value" name="okp:consulting.decimal"> <validator type="dec" /> <validator type="req" /> <validator type="maxlen" parameter="6" /></input>Regular expression
Section titled “Regular expression”You can use a regular expression if you want a validation that is not included among these predefined validators. For example, imagine you want to restrict an input to lowercase ASCII characters:
<input label="Lowercase value" name="regExp"> <validator type="regexp" parameter="[a-z]+" /></input>