Skip to main content

List of validation options

Metafield definitions can have validation options. Validation options enable you to apply additional constraints to the data that a metafield can store, such as a minimum or maximum value, or a regular expression. The type of the metafield definition determines which validation options are available.


You can include a validation option for a metafield definition using the validation name and a corresponding value. The appropriate value depends on the metafield type that the validation applies to. For more information about the supported formats and units of measurement available for each type, refer to Metafield types.


Anchor to Supported validation optionsSupported validation options

The following table describes the validation options available for metafield definitions. Refer to the examples for validation option code snippets.

Validation optionDescriptionSupported typesUse cases
Minimum lengthSets the minimum length of a text value
  • single_line_text_field
  • multi_line_text_field
  • A blog summary needs to be at least 100 characters, so that it provides enough detail.
  • A value such as a zip code needs to have an exact character length, so set the minimum and maximum lengths to the same value.
Maximum lengthSets the maximum length of a text value
  • single_line_text_field
  • multi_line_text_field
  • A blog summary or a product description needs to have a maximum length of 150 characters so that it fits in a designated area of your page.
  • A value such as a phone number needs to have an exact character length of ten, so set minimum length and maximum length to 10.
Regular expressionSets a regular expression. Shopify supports RE2.
  • single_line_text_field
  • multi_line_text_field
  • An email field requires an @ symbol followed by a . and some text.
  • A serial number needs to start with a specific set of characters.
Allowed domainsA list of allowed domains.url
  • Allow links to specific social media sites at the bottom of an article.
  • Allow links to other pages within your site for a list of similar products.
ChoicesA list of up to 128 predefined options that limit the values allowed for the metafield. The choices value has a maximum of 300,000 characters.single_line_text_field
  • The flavor profile field for coffee products allows the following choices: Floral, Sweet, Nutty, and Other.
  • The field for sizing fits for a product allows the following choices: True to size, Runs large, Runs small.
File type optionsSets a list of file type options. Leaving this empty allows all files, regardless of type.

Valid values: Image, Video.
file_reference
  • A file reference from a blog to an author photo needs to be to an image file type.
  • A file reference to a demonstration video in MP4 format.
  • A file reference from an order to product instructions in PDF format.
Maximum precisionSets the maximum number of decimal places to store for a decimal numbernumber_decimal
  • A version number field needs to accept a number with one decimal place.
  • A specification field for a product needs to have a maximum of three decimal places.
Minimum dateSets the minimum date in ISO 8601 formatdateThe date field for an expiry date or a product release needs to be after a specific date.
Maximum dateSets the maximum date in ISO 8601 formatdateThe date for future product availability can't be later than a specific date.
Minimum datetimeSets the minimum date and time in ISO 8601 formatdate_timeA product release occurs on a specific date at midnight, and the product won't display before that date and time.
Maximum datetimeSets the maximum date and time in ISO 8601 formatdate_timeA customer loyalty reward expires on a specific date and time. The reward can't be used after that date and time.
Minimum weightSets the minimum weightweightA bundled product weight field needs to have a maximum allowed weight.
Maximum weightSets the maximum weightweightAn order requires a minimum weight for shipping.
Minimum volumeSets the minimum volumevolume
  • A product volume field needs to have a specific minimum volume.
  • A product needs to have an exact volume, so you set minimum volume and maximum volume to the same value.
Maximum volumeSets the maximum volumevolume
  • A product volume field needs to have certain maximum volume.
  • A product needs to have an exact volume, so you set minimum volume and maximum volume to the same value.
Minimum dimensionSets the minimum dimensiondimensionA product needs to have a minimum length, width, or height.
Maximum dimensionSets the maximum dimensiondimensionA product needs to have a maximum length, width, or height.
Minimum integerSets the minimum integer numbernumber_integerA product number needs to be within a specific range of numbers, so you set the minimum and maximum integer validations to create the range.
Maximum integerSets the maximum integer numbernumber_integerA product number needs to be within a specific range of numbers, so you set the minimum and maximum integer validations to create the range.
Minimum decimalSets the minimum decimal numbernumber_decimalA product version field needs to accept a version number that's greater than a specific decimal number, such as 0.5.
Maximum decimalSets the maximum decimal numbernumber_decimalA product version field needs to accept a version number that's less than a specific decimal number, such as 1.99.
Metaobject definitionSets the metaobject definition that a reference must point to
  • metaobject_reference
  • list.metaobject_reference
A product refers to a Designer metaobject.
Multiple metaobject definitionsSets the permitted metaobject definitions that can be referred to
  • mixed_reference
  • list.mixed_reference
  • A product that references a list of different Material metaobjects.
  • A dynamic placeholder reference that can support a union set of metaobject definitions.
JSON schemaSets the permitted JSON format. The JSON schema provides an example of a standard way to structure your JSON, and contains information about valid data types and the key descriptions. The JSON schema has a maximum of 300,000 characters.jsonData from a 3rd-party app must match a specific JSON schema.
Product taxonomy attributeSets the product taxonomy attribute that a reference must point to
  • product_taxonomy_value_reference
  • list.product_taxonomy_value_reference
  • A product that references a Color taxonomy value.
  • A product that references a list of Material taxonomy values.
List minimumSets the minimum number of items in a listAny list type
  • A product must have at least two related products.
  • A blog post must have at least one tag.
List maximumSets the maximum number of items in a listAny list type
  • A product can have up to five related products.
  • A blog post can have up to 10 tags.

This section provides examples of each validation option.

The following example validates the minimum length of a text value to eight characters.

validations: [{
name: "min",
value: "8"
}]

The following example validates the maximum length of a text value to 25 characters.

validations: [{
name: "max",
value: "25"
}]

The following example validates a regular expression that matches the pattern (@)(.+)$.

validations: [{
name: "regex",
value: "(@)(.+)$"
}]

The following example validates shopify.com against a list of allowed domains.

validations: [{
name: "allowed_domains",
value: "[\"shopify.com\"]"
}]

The following example validates the values allowed for the metafield: red, green, blue.

validations: [{
name: "choices",
value: "[\"red\", \"green\", \"blue\"]"
}]

The following example validates the allowed file type options: Image, Video.

validations: [{
name: "file_type_options",
value: "[\"Image\",\"Video\"]"
}]

The following example validates that the maximum number of decimal places to store for a floating-point number is two.

validations: [{
name: "max_precision",
value: "2"
}]

The following example validates the setting for the minimum date in ISO 8601 format.

validations: [{
name: "min",
value: "2022-01-01"
}]

The following example validates the setting for the maximum date in ISO 8601 format.

validations: [{
name: "max",
value: "2022-03-03"
}]

The following example validates the setting for the minimum date and time in ISO 8601 format.

validations: [{
name: "min",
value: "2022-03-03T16:30:00"
}]

The following example validates the setting for the maximum date and time in ISO 8601 format.

validations: [{
name: "max",
value: "2022-03-03T16:30:00"
}]

The following example validates a setting for the minimum weight to be ten grams.

validations: [{
name: "min",
value: "{\"unit\":\"g\",\"value\":10}"
}]

The following example validates a setting for the maximum weight to be 50 grams.

validations: [{
name: "max",
value: "{\"unit\":\"g\",\"value\":50}"
}]

The following example validates a setting for the minimum volume to be five milliliters.

validations: [{
name: "min",
value: "{\"unit\":\"ml\",\"value\":5}"
}]

The following example validates a setting for the maximum volume to be 50 milliliters.

validations: [{
name: "max",
value: "{\"unit\":\"ml\",\"value\":50}"
}]

The following example validates a setting for the minimum dimension to be five centimeters.

validations: [{
name: "min",
value: "{\"unit\":\"cm\",\"value\":5}"
}]

The following example validates a setting for the maximum dimension to be 50 centimeters.

validations: [{
name: "max",
value: "{\"unit\":\"cm\",\"value\":50}"
}]

The following example validates a setting for the minimum integer number to be nine.

validations: [{
name: "min",
value: "9"
}]

The following example validates a setting for the maximum integer number to be 15.

validations: [{
name: "max",
value: "15"
}]

The following example validates a setting for the minimum decimal number to be 0.5.

validations: [{
name: "min",
value: "0.5"
}]

The following example validates a setting for the maximum decimal number to be 1.99.

validations: [{
name: "max",
value: "1.99"
}]

Anchor to Metaobject definitionMetaobject definition

The following example validates a setting for the metaobject definition that a reference must point to.

validations: [{
name: "metaobject_definition_id",
value: "gid://shopify/MetaobjectDefinition/123"
}]

Anchor to Multiple metaobject definitionsMultiple metaobject definitions

The following example validates a setting for the permitted metaobject definitions that can be referred to.

validations: [{
name: "metaobject_definition_ids",
value: "[\"gid://shopify/MetaobjectDefinition/123\",\"gid://shopify/MetaobjectDefinition/456\"]"
}]

The following example validates a setting for the permitted JSON format.

validations: [{
name: "schema",
value: "{
\"\$id\": \"https://example.com/person.schema.json\",
\"\$schema\": \"https://json-schema.org/draft/2020-12/schema\",
\"title\": \"Person\",
\"type\": \"object\",
\"properties\": {
\"firstName\": {
\"type\": \"string\",
\"description\": \"The person's first name.\"
},
\"lastName\": {
\"type\": \"string\",
\"description\": \"The person's last name.\"
},
\"age\": {
\"description\": \"Age in years >= 0.\",
\"type\": \"integer\",
\"minimum\": 0
}
}
}"
}]

Anchor to Product taxonomy attributeProduct taxonomy attribute

The following example validates a setting for the product taxonomy attribute that a reference must point to.

validations: [{
name: "product_taxonomy_attribute_handle",
value: "style"
}]

The following example validates that a list must contain at least two items.

validations: [{
name: "list.min",
value: "2"
}]

The following example validates that a list can contain up to five items.

validations: [{
name: "list.max",
value: "5"
}]


Was this page helpful?