Skip to content

Validators

Validators define acceptable values for fields.

Specifying validators for all applicable entities is strongly recommended. Omitting validators can expose forms to security risks and cause unexpected behavior. If the value is validated and encapsulated downstream, add an empty array to suppress the warning:

"validators": []

Common Properties

  • type* specifies which validator type to use.
  • errorMsg is an optional parameter used to specify a custom error message that displays when validation fails. UCC provides default error messages.

String

Properties

  • minLength* specifies the minimum number of characters allowed.
  • maxLength* specifies the maximum number of characters allowed.

See the following example usage:

{
  "type": "text",
  "label": "Index Name",
  "validators": [
      {
        "type": "string",
        "errorMsg": "Length of index name should be between 1 to 80 characters.",
        "minLength": 1,
        "maxLength": 80
      }
  ],
  "field": "index_name"
}

Regex

Properties

  • pattern* is a Regex pattern.

See the following example usage:

{
  "type": "text",
  "label": "Name",
  "validators": [
      {
        "type": "regex",
        "errorMsg": "Input Name must begin with a letter and consist exclusively of alphanumeric characters and underscores.",
        "pattern": "^[a-zA-Z]\\w*$"
      }
  ],
  "field": "name_field"
}

Number

Properties

  • range* is the range within which the target value should fall.
  • isInteger is the boolean which target only integer value if sets true. Default value is false

See the following example usage:

{
  "type": "text",
  "label": "Port",
  "validators": [
      {
        "type": "number",
        "range": [1, 65535],
        "isInteger": true
      }
  ],
  "field": "port"
}

URL

No parameters are needed.

If you’re using a regexp internally, this regex checks whether a field value is a URL or not.

See the following example usage:

{
  "type": "text",
  "label": "Url",
  "validators": [
      {
        "type": "url",
      }
  ],
  "field": "url"
}

Email

No parameters are needed.

Using a regexp internally is recommended by WHATWG.

See the following example usage:

{
  "type": "text",
  "label": "Email",
  "validators": [
      {
        "type": "email",
      }
  ],
  "field": "email"
}

IPV4

No parameters are needed.

Internally, it checks the IPV4 address using this regex.

See the following example usage:

{
    "field": "testIpv4",
    "label": "Test Ipv4",
    "type": "text",
    "validators": [
        {
            "type": "ipv4"
        }
    ]
}

Date

No parameters are needed.

It is validated if the field’s value is a date in the ISO 8601 format. It uses the regex from moment.js.

See the following example usage:

{
    "field": "testDate",
    "label": "Test Date",
    "type": "text",
    "validators": [
        {
            "type": "date"
        }
    ]
}

Combinations

You can combine multiple validators in a single array.

Example:

{
    "field": "https_url",
    "label": "HTTPS only URL",
    "type": "text",
    "validators": [
        {
            "type": "url"
        },
        {
          "type": "regex",
          "errorMsg": "HTTPS only",
          "pattern": "^https:\/\/"
        }
    ]
}