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.
Anchor to How it worksHow it works
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 option | Description | Supported types | Use cases |
---|---|---|---|
Minimum length | Sets the minimum length of a text value |
|
|
Maximum length | Sets the maximum length of a text value |
|
|
Regular expression | Sets a regular expression. Shopify supports RE2. |
|
|
Allowed domains | A list of allowed domains. | url |
|
Choices | A 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 |
|
File type options | Sets a list of file type options. Leaving this empty allows all files, regardless of type. Valid values: Image , Video . | file_reference |
|
Maximum precision | Sets the maximum number of decimal places to store for a decimal number | number_decimal |
|
Minimum date | Sets the minimum date in ISO 8601 format | date | The date field for an expiry date or a product release needs to be after a specific date. |
Maximum date | Sets the maximum date in ISO 8601 format | date | The date for future product availability can't be later than a specific date. |
Minimum datetime | Sets the minimum date and time in ISO 8601 format | date_time | A product release occurs on a specific date at midnight, and the product won't display before that date and time. |
Maximum datetime | Sets the maximum date and time in ISO 8601 format | date_time | A customer loyalty reward expires on a specific date and time. The reward can't be used after that date and time. |
Minimum weight | Sets the minimum weight | weight | A bundled product weight field needs to have a maximum allowed weight. |
Maximum weight | Sets the maximum weight | weight | An order requires a minimum weight for shipping. |
Minimum volume | Sets the minimum volume | volume |
|
Maximum volume | Sets the maximum volume | volume |
|
Minimum dimension | Sets the minimum dimension | dimension | A product needs to have a minimum length, width, or height. |
Maximum dimension | Sets the maximum dimension | dimension | A product needs to have a maximum length, width, or height. |
Minimum integer | Sets the minimum integer number | number_integer | A 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 integer | Sets the maximum integer number | number_integer | A 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 decimal | Sets the minimum decimal number | number_decimal | A product version field needs to accept a version number that's greater than a specific decimal number, such as 0.5 . |
Maximum decimal | Sets the maximum decimal number | number_decimal | A product version field needs to accept a version number that's less than a specific decimal number, such as 1.99 . |
Metaobject definition | Sets the metaobject definition that a reference must point to |
| A product refers to a Designer metaobject. |
Multiple metaobject definitions | Sets the permitted metaobject definitions that can be referred to |
|
|
JSON schema | Sets 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. | json | Data from a 3rd-party app must match a specific JSON schema. |
Product taxonomy attribute | Sets the product taxonomy attribute that a reference must point to |
|
|
List minimum | Sets the minimum number of items in a list | Any list type |
|
List maximum | Sets the maximum number of items in a list | Any list type |
|
Anchor to ExamplesExamples
This section provides examples of each validation option.
Anchor to Minimum lengthMinimum length
The following example validates the minimum length of a text value to eight characters.
Anchor to Maximum lengthMaximum length
The following example validates the maximum length of a text value to 25 characters.
Anchor to Regular expressionRegular expression
The following example validates a regular expression that matches the pattern (@)(.+)$
.
Anchor to Allowed domainsAllowed domains
The following example validates shopify.com
against a list of allowed domains.
Anchor to ChoicesChoices
The following example validates the values allowed for the metafield: red
, green
, blue
.
Anchor to File type optionsFile type options
The following example validates the allowed file type options: Image
, Video
.
Anchor to Maximum precisionMaximum precision
The following example validates that the maximum number of decimal places to store for a floating-point number is two.
Anchor to Minimum dateMinimum date
The following example validates the setting for the minimum date in ISO 8601 format.
Anchor to Maximum dateMaximum date
The following example validates the setting for the maximum date in ISO 8601 format.
Anchor to Minimum datetimeMinimum datetime
The following example validates the setting for the minimum date and time in ISO 8601 format.
Anchor to Maximum datetimeMaximum datetime
The following example validates the setting for the maximum date and time in ISO 8601 format.
Anchor to Minimum weightMinimum weight
The following example validates a setting for the minimum weight to be ten grams.
Anchor to Maximum weightMaximum weight
The following example validates a setting for the maximum weight to be 50 grams.
Anchor to Minimum volumeMinimum volume
The following example validates a setting for the minimum volume to be five milliliters.
Anchor to Maximum volumeMaximum volume
The following example validates a setting for the maximum volume to be 50 milliliters.
Anchor to Minimum dimensionMinimum dimension
The following example validates a setting for the minimum dimension to be five centimeters.
Anchor to Maximum dimensionMaximum dimension
The following example validates a setting for the maximum dimension to be 50 centimeters.
Anchor to Minimum integerMinimum integer
The following example validates a setting for the minimum integer number to be nine.
Anchor to Maximum integerMaximum integer
The following example validates a setting for the maximum integer number to be 15.
Anchor to Minimum decimalMinimum decimal
The following example validates a setting for the minimum decimal number to be 0.5.
Anchor to Maximum decimalMaximum decimal
The following example validates a setting for the maximum decimal number to be 1.99.
Anchor to Metaobject definitionMetaobject definition
The following example validates a setting for the metaobject definition that a reference must point to.
Anchor to Multiple metaobject definitionsMultiple metaobject definitions
The following example validates a setting for the permitted metaobject definitions that can be referred to.
Anchor to JSON schemaJSON schema
The following example validates a setting for the permitted JSON format.
Anchor to Product taxonomy attributeProduct taxonomy attribute
The following example validates a setting for the product taxonomy attribute that a reference must point to.
Anchor to List minimumList minimum
The following example validates that a list must contain at least two items.
Anchor to List maximumList maximum
The following example validates that a list can contain up to five items.
Anchor to Next stepsNext steps
- Learn how to manage metafield definitions using the GraphQL Admin API.