Skip to documentation content

Form Field Validators

Form Field Validators

Validators that check a form field value before submit, including {{ validators }}, the shared {{ validator }} shape, and each typed validator object.

Some field types expose a {{ validators }} object; others do not. That object is not polymorphic: object_type is always validators, and validators holds a flat list of validator objects.

Each item in that list is polymorphic. Liquid exposes the shared shape as {{ validator }}, but at runtime each item is one of the typed validator objects on this page. Use object_type or type to tell which implementing type you have.

Unlike conditions, multiple validators are not grouped with and/or. They sit in one flat list. {{ validator }} documents only the shared properties (object_type, is_valid, type, and message). Typed objects add the rest.

These are form-field validators, not Liquid {% if %} operators.

{{ validators }}

The validators object on a form field. This object is not polymorphic: object_type is always validators. Some field types expose it; others do not. validators holds a flat list of validator objects, and each of those is one of the typed validator objects.

Properties
Properties of {{ validators }} objects
Name Type Description
is_valid boolean Will be true if validators contains one or more validators
object_type string Will always be "validators"
validators list The list of validator objects for the current field. Each item is one of the typed {{ validator }} objects
output string {JSON object}
Example Show a hint only when a field has validatorsNot every field type exposes {{ validators }}. Guard on is_valid before reading its list, since a field with none still returns the object.
Liquid
{%- if form_field.validators.is_valid -%}
	<p class="field-hint">{{ form_field.validators.validators | size }} rule(s) apply to this field.</p>
{%- endif -%}
Example Fall back to a generic message when a validator has none{{ validator }} always has message, but it is often blank so the runtime default applies. Build your own fallback with the type when you render messages yourself.
Liquid
{%- for v in form_field.validators.validators -%}
	<li data-rule="{{ v.type }}">{{ v.message | default: v.type | append: " validation failed" }}</li>
{%- endfor -%}

{{ validator }}

{{ validator }} is the shared shape for one form-field validator. It is not a separate runtime type: each item in the validators list is one of the typed validator objects on this page (email_validator, maxsize_validator, and the rest). Use object_type or type to tell which implementing type you have.

Properties
Properties of {{ validator }} objects
Name Type Description
is_valid boolean Will always be true
object_type string The object_type of the implementing validator (for example email_validator or maxsize_validator)
type string The type of validator. Each type corresponds to a different validator object which has its own additional properties
message string The message to display when this validator fails. If message is null or empty, a reasonable default is used
output string {JSON object}

Typed validator objects add further properties that are not listed here (for example value or field_id). See each type on this page.

Example Fall back to a generic message when a validator has none{{ validator }} always has message, but it is often blank so the runtime default applies. Build your own fallback with the type when you render messages yourself.
Liquid
{%- for v in form_field.validators.validators -%}
	<li data-rule="{{ v.type }}">{{ v.message | default: v.type | append: " validation failed" }}</li>
{%- endfor -%}

{{ alphanumeric_validator }}

A form-field validator that requires the value to contain only letters and numbers.

Properties
Properties of {{ alphanumeric_validator }} objects
Name Type Description
is_valid boolean Will always be true
object_type string Will always be "alphanumeric_validator"
type string Will always be "alphanumeric"
message string The message to display when this validator fails. If message is null or empty, a reasonable default is used
output string {JSON object}
Example Show a required-format hint for a validatoralphanumeric_validator, decimal_validator, email_validator, number_validator, phone_validator, and url_validator all share the same shape — a format check with no extra properties beyond message.
Liquid
{%- for v in form_field.validators.validators -%}
	<li>Must be a valid {{ v.type }}.</li>
{%- endfor -%}

{{ decimal_validator }}

A form-field validator that requires the value to be a decimal number.

Properties
Properties of {{ decimal_validator }} objects
Name Type Description
is_valid boolean Will always be true
object_type string Will always be "decimal_validator"
type string Will always be "decimal"
message string The message to display when this validator fails. If message is null or empty, a reasonable default is used
output string {JSON object}
Example Show a required-format hint for a validatoralphanumeric_validator, decimal_validator, email_validator, number_validator, phone_validator, and url_validator all share the same shape — a format check with no extra properties beyond message.
Liquid
{%- for v in form_field.validators.validators -%}
	<li>Must be a valid {{ v.type }}.</li>
{%- endfor -%}

{{ different_validator }}

A form-field validator that requires the value to differ from another field.

Properties
Properties of {{ different_validator }} objects
Name Type Description
is_valid boolean Will always be true
object_type string Will always be "different_validator"
type string Will always be "different"
message string The message to display when this validator fails. If message is null or empty, a reasonable default is used
field_id string The field_id of the other field that this value must differ from
output string {JSON object}
Example Compare a validator against another fielddifferent_validator and same_validator both compare this field to another field by field_id, requiring the values to differ or match.
Liquid
{%- for v in form_field.validators.validators -%}
	{%- if v.object_type == "different_validator" -%}
		<li>Must differ from {{ v.field_id }}</li>
	{%- elsif v.object_type == "same_validator" -%}
		<li>Must match {{ v.field_id }}</li>
	{%- endif -%}
{%- endfor -%}

{{ email_validator }}

A form-field validator that requires the value to be an email address.

Properties
Properties of {{ email_validator }} objects
Name Type Description
is_valid boolean Will always be true
object_type string Will always be "email_validator"
type string Will always be "email"
message string The message to display when this validator fails. If message is null or empty, a reasonable default is used
output string {JSON object}
Example Show a required-format hint for a validatoralphanumeric_validator, decimal_validator, email_validator, number_validator, phone_validator, and url_validator all share the same shape — a format check with no extra properties beyond message.
Liquid
{%- for v in form_field.validators.validators -%}
	<li>Must be a valid {{ v.type }}.</li>
{%- endfor -%}

{{ eq_validator }}

A form-field validator that requires the value to equal a given value.

Properties
Properties of {{ eq_validator }} objects
Name Type Description
is_valid boolean Will always be true
object_type string Will always be "eq_validator"
type string Will always be "eq"
message string The message to display when this validator fails. If message is null or empty, a reasonable default is used
value string The value that the field must equal
invert boolean When true, the validator requires the field value not to equal the given value
output string {JSON object}
Example Require a field to equal, or not equal, a fixed valueeq_validator and not_validator both compare against a literal value, never another field — they are opposite tests of the same shape.
Liquid
{%- for v in form_field.validators.validators -%}
	{%- if v.object_type == "eq_validator" -%}
		<li>Must equal "{{ v.value }}"</li>
	{%- elsif v.object_type == "not_validator" -%}
		<li>Must not equal "{{ v.value }}"</li>
	{%- endif -%}
{%- endfor -%}

{{ gt_validator }}

A form-field validator that requires the value to be greater than a given value or another field.

Properties
Properties of {{ gt_validator }} objects
Name Type Description
is_valid boolean Will always be true
object_type string Will always be "gt_validator"
type string Will always be "gt"
message string The message to display when this validator fails. If message is null or empty, a reasonable default is used
value string The value that the field must be greater than, when field_id is not set
field_id string When set, the field_id of the other field that this value must be greater than
output string {JSON object}
Example Read a validator that compares to a value or another fieldgt_validator and gte_validator compare against either a literal value or another field — field_id is set only when comparing to a field, so value is the fallback.
Liquid
{%- for v in form_field.validators.validators -%}
	{%- if v.object_type == "gt_validator" -%}
		<li>Must be greater than {{ v.field_id | default: v.value }}</li>
	{%- elsif v.object_type == "gte_validator" -%}
		<li>Must be {{ v.field_id | default: v.value }} or greater</li>
	{%- endif -%}
{%- endfor -%}

{{ gte_validator }}

A form-field validator that requires the value to be greater than or equal to a given value or another field.

Properties
Properties of {{ gte_validator }} objects
Name Type Description
is_valid boolean Will always be true
object_type string Will always be "gte_validator"
type string Will always be "gte"
message string The message to display when this validator fails. If message is null or empty, a reasonable default is used
value string The value that the field must be greater than or equal to, when field_id is not set
field_id string When set, the field_id of the other field that this value must be greater than or equal to
output string {JSON object}
Example Read a validator that compares to a value or another fieldgt_validator and gte_validator compare against either a literal value or another field — field_id is set only when comparing to a field, so value is the fallback.
Liquid
{%- for v in form_field.validators.validators -%}
	{%- if v.object_type == "gt_validator" -%}
		<li>Must be greater than {{ v.field_id | default: v.value }}</li>
	{%- elsif v.object_type == "gte_validator" -%}
		<li>Must be {{ v.field_id | default: v.value }} or greater</li>
	{%- endif -%}
{%- endfor -%}

{{ lt_validator }}

A form-field validator that requires the value to be less than a given value or another field.

Properties
Properties of {{ lt_validator }} objects
Name Type Description
is_valid boolean Will always be true
object_type string Will always be "lt_validator"
type string Will always be "lt"
message string The message to display when this validator fails. If message is null or empty, a reasonable default is used
value string The value that the field must be less than, when field_id is not set
field_id string When set, the field_id of the other field that this value must be less than
output string {JSON object}
Example Read a validator that compares to a value or another field, on the low sidelt_validator and lte_validator compare against either a literal value or another field — field_id is set only when comparing to a field, so value is the fallback.
Liquid
{%- for v in form_field.validators.validators -%}
	{%- if v.object_type == "lt_validator" -%}
		<li>Must be less than {{ v.field_id | default: v.value }}</li>
	{%- elsif v.object_type == "lte_validator" -%}
		<li>Must be {{ v.field_id | default: v.value }} or less</li>
	{%- endif -%}
{%- endfor -%}

{{ lte_validator }}

A form-field validator that requires the value to be less than or equal to a given value or another field.

Properties
Properties of {{ lte_validator }} objects
Name Type Description
is_valid boolean Will always be true
object_type string Will always be "lte_validator"
type string Will always be "lte"
message string The message to display when this validator fails. If message is null or empty, a reasonable default is used
value string The value that the field must be less than or equal to, when field_id is not set
field_id string When set, the field_id of the other field that this value must be less than or equal to
output string {JSON object}
Example Read a validator that compares to a value or another field, on the low sidelt_validator and lte_validator compare against either a literal value or another field — field_id is set only when comparing to a field, so value is the fallback.
Liquid
{%- for v in form_field.validators.validators -%}
	{%- if v.object_type == "lt_validator" -%}
		<li>Must be less than {{ v.field_id | default: v.value }}</li>
	{%- elsif v.object_type == "lte_validator" -%}
		<li>Must be {{ v.field_id | default: v.value }} or less</li>
	{%- endif -%}
{%- endfor -%}

{{ maxitems_validator }}

A form-field validator that requires a list field to have at most a given number of selected items.

Properties
Properties of {{ maxitems_validator }} objects
Name Type Description
is_valid boolean Will always be true
object_type string Will always be "maxitems_validator"
type string Will always be "maxitems"
message string The message to display when this validator fails. If message is null or empty, a reasonable default is used
value integer The maximum number of selected items
output string {JSON object}
Example Enforce a selection-count validator's limitmaxitems_validator and minitems_validator both count selections on a list field; value holds the limit, same shape as their condition counterparts.
Liquid
{%- for v in form_field.validators.validators -%}
	{%- if v.object_type == "maxitems_validator" -%}
		<li>Choose {{ v.value }} or fewer</li>
	{%- elsif v.object_type == "minitems_validator" -%}
		<li>Choose at least {{ v.value }}</li>
	{%- endif -%}
{%- endfor -%}

{{ maxlength_validator }}

A form-field validator that requires the value to be no longer than a given number of characters.

Properties
Properties of {{ maxlength_validator }} objects
Name Type Description
is_valid boolean Will always be true
object_type string Will always be "maxlength_validator"
type string Will always be "maxlength"
message string The message to display when this validator fails. If message is null or empty, a reasonable default is used
value integer The maximum number of characters allowed
output string {JSON object}
Example Enforce a character-count validator's limitmaxlength_validator and minlength_validator both count characters in a text value; value holds the limit.
Liquid
{%- for v in form_field.validators.validators -%}
	{%- if v.object_type == "maxlength_validator" -%}
		<li>{{ v.value }} characters or fewer</li>
	{%- elsif v.object_type == "minlength_validator" -%}
		<li>At least {{ v.value }} characters</li>
	{%- endif -%}
{%- endfor -%}

{{ maxsize_validator }}

A form-field validator that limits the size of an uploaded file.

Properties
Properties of {{ maxsize_validator }} objects
Name Type Description
is_valid boolean Will always be true
object_type string Will always be "maxsize_validator"
type string Will always be "maxsize"
message string The message to display when this validator fails. If message is null or empty, a reasonable default is used
value integer The maximum allowed size for an uploaded file
output string {JSON object}
Example Show the upload size limit from a maxsize_validatormaxsize_validator is the only typed validator that limits an uploaded file rather than a text, number, or list value.
Liquid
{%- for v in form_field.validators.validators -%}
	{%- if v.object_type == "maxsize_validator" -%}
		<li>File must be under {{ v.value }}</li>
	{%- endif -%}
{%- endfor -%}

{{ minitems_validator }}

A form-field validator that requires a list field to have at least a given number of selected items.

Properties
Properties of {{ minitems_validator }} objects
Name Type Description
is_valid boolean Will always be true
object_type string Will always be "minitems_validator"
type string Will always be "minitems"
message string The message to display when this validator fails. If message is null or empty, a reasonable default is used
value integer The minimum number of selected items
output string {JSON object}
Example Enforce a selection-count validator's limitmaxitems_validator and minitems_validator both count selections on a list field; value holds the limit, same shape as their condition counterparts.
Liquid
{%- for v in form_field.validators.validators -%}
	{%- if v.object_type == "maxitems_validator" -%}
		<li>Choose {{ v.value }} or fewer</li>
	{%- elsif v.object_type == "minitems_validator" -%}
		<li>Choose at least {{ v.value }}</li>
	{%- endif -%}
{%- endfor -%}

{{ minlength_validator }}

A form-field validator that requires the value to be at least a given number of characters.

Properties
Properties of {{ minlength_validator }} objects
Name Type Description
is_valid boolean Will always be true
object_type string Will always be "minlength_validator"
type string Will always be "minlength"
message string The message to display when this validator fails. If message is null or empty, a reasonable default is used
value integer The minimum number of characters required
output string {JSON object}
Example Enforce a character-count validator's limitmaxlength_validator and minlength_validator both count characters in a text value; value holds the limit.
Liquid
{%- for v in form_field.validators.validators -%}
	{%- if v.object_type == "maxlength_validator" -%}
		<li>{{ v.value }} characters or fewer</li>
	{%- elsif v.object_type == "minlength_validator" -%}
		<li>At least {{ v.value }} characters</li>
	{%- endif -%}
{%- endfor -%}

{{ not_validator }}

A form-field validator that requires the value not to equal a given value.

Properties
Properties of {{ not_validator }} objects
Name Type Description
is_valid boolean Will always be true
object_type string Will always be "not_validator"
type string Will always be "not"
message string The message to display when this validator fails. If message is null or empty, a reasonable default is used
value string The value that the field must not equal
output string {JSON object}
Example Require a field to equal, or not equal, a fixed valueeq_validator and not_validator both compare against a literal value, never another field — they are opposite tests of the same shape.
Liquid
{%- for v in form_field.validators.validators -%}
	{%- if v.object_type == "eq_validator" -%}
		<li>Must equal "{{ v.value }}"</li>
	{%- elsif v.object_type == "not_validator" -%}
		<li>Must not equal "{{ v.value }}"</li>
	{%- endif -%}
{%- endfor -%}

{{ number_validator }}

A form-field validator that requires the value to be an integer number.

Properties
Properties of {{ number_validator }} objects
Name Type Description
is_valid boolean Will always be true
object_type string Will always be "number_validator"
type string Will always be "number"
message string The message to display when this validator fails. If message is null or empty, a reasonable default is used
output string {JSON object}
Example Show a required-format hint for a validatoralphanumeric_validator, decimal_validator, email_validator, number_validator, phone_validator, and url_validator all share the same shape — a format check with no extra properties beyond message.
Liquid
{%- for v in form_field.validators.validators -%}
	<li>Must be a valid {{ v.type }}.</li>
{%- endfor -%}

{{ phone_validator }}

A form-field validator that requires the value to be a phone number.

Properties
Properties of {{ phone_validator }} objects
Name Type Description
is_valid boolean Will always be true
object_type string Will always be "phone_validator"
type string Will always be "phone"
message string The message to display when this validator fails. If message is null or empty, a reasonable default is used
output string {JSON object}
Example Show a required-format hint for a validatoralphanumeric_validator, decimal_validator, email_validator, number_validator, phone_validator, and url_validator all share the same shape — a format check with no extra properties beyond message.
Liquid
{%- for v in form_field.validators.validators -%}
	<li>Must be a valid {{ v.type }}.</li>
{%- endfor -%}

{{ regex_validator }}

A form-field validator that requires the value to match a regular expression.

Properties
Properties of {{ regex_validator }} objects
Name Type Description
is_valid boolean Will always be true
object_type string Will always be "regex_validator"
type string Will always be "regex"
message string The message to display when this validator fails. If message is null or empty, a reasonable default is used
value string The regular expression to test the field value against
invert boolean When true, the validator requires the field value not to match the pattern
output string {JSON object}
Example Show the pattern a regex_validator requiresregex_validator tests the field value against value, a regular expression, and can invert the test to require a non-match instead.
Liquid
{%- for v in form_field.validators.validators -%}
	{%- if v.object_type == "regex_validator" -%}
		<li>Must match pattern {{ v.value }}</li>
	{%- endif -%}
{%- endfor -%}

{{ same_validator }}

A form-field validator that requires the value to match another field.

Properties
Properties of {{ same_validator }} objects
Name Type Description
is_valid boolean Will always be true
object_type string Will always be "same_validator"
type string Will always be "same"
message string The message to display when this validator fails. If message is null or empty, a reasonable default is used
field_id string The field_id of the other field that this value must match
invert boolean When true, the validator requires the field value to differ from the other field
output string {JSON object}
Example Compare a validator against another fielddifferent_validator and same_validator both compare this field to another field by field_id, requiring the values to differ or match.
Liquid
{%- for v in form_field.validators.validators -%}
	{%- if v.object_type == "different_validator" -%}
		<li>Must differ from {{ v.field_id }}</li>
	{%- elsif v.object_type == "same_validator" -%}
		<li>Must match {{ v.field_id }}</li>
	{%- endif -%}
{%- endfor -%}

{{ url_validator }}

A form-field validator that requires the value to be a URL.

Properties
Properties of {{ url_validator }} objects
Name Type Description
is_valid boolean Will always be true
object_type string Will always be "url_validator"
type string Will always be "url"
message string The message to display when this validator fails. If message is null or empty, a reasonable default is used
output string {JSON object}
Example Show a required-format hint for a validatoralphanumeric_validator, decimal_validator, email_validator, number_validator, phone_validator, and url_validator all share the same shape — a format check with no extra properties beyond message.
Liquid
{%- for v in form_field.validators.validators -%}
	<li>Must be a valid {{ v.type }}.</li>
{%- endfor -%}