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.
How it works
Anchor link to section titled "How 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.
Learn more about creating a metafield definition with validation options. Refer to the following table for more examples.
Supported validation options
Anchor link to section titled "Supported 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. | 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. | json |
Data from a 3rd-party app must match a specific JSON schema. |
This section provides examples of each validation option.
Minimum length
Anchor link to section titled "Minimum length"The following example validates the minimum length of a text value to eight characters.
Maximum length
Anchor link to section titled "Maximum length"The following example validates the maximum length of a text value to 25 characters.
Regular expression
Anchor link to section titled "Regular expression"The following example validates a regular expression that matches the pattern (@)(.+)$
.
Allowed domains
Anchor link to section titled "Allowed domains"The following example validates shopify.com
against a list of allowed domains.
The following example validates the values allowed for the metafield: red
, green
, blue
.
File type options
Anchor link to section titled "File type options"The following example validates the allowed file type options: Image
, Video
.
Maximum precision
Anchor link to section titled "Maximum precision"The following example validates that the maximum number of decimal places to store for a floating-point number is two.
Minimum date
Anchor link to section titled "Minimum date"The following example validates the setting for the minimum date in ISO 8601 format.
Maximum date
Anchor link to section titled "Maximum date"The following example validates the setting for the maximum date in ISO 8601 format.
Minimum datetime
Anchor link to section titled "Minimum datetime"The following example validates the setting for the minimum date and time in ISO 8601 format.
Maximum datetime
Anchor link to section titled "Maximum datetime"The following example validates the setting for the maximum date and time in ISO 8601 format.
Minimum weight
Anchor link to section titled "Minimum weight"The following example validates a setting for the minimum weight to be ten grams.
Maximum weight
Anchor link to section titled "Maximum weight"The following example validates a setting for the maximum weight to be 50 grams.
Minimum volume
Anchor link to section titled "Minimum volume"The following example validates a setting for the minimum volume to be five milliliters.
Maximum volume
Anchor link to section titled "Maximum volume"The following example validates a setting for the maximum volume to be 50 milliliters.
Minimum dimension
Anchor link to section titled "Minimum dimension"The following example validates a setting for the minimum dimension to be five centimeters.
Maximum dimension
Anchor link to section titled "Maximum dimension"The following example validates a setting for the maximum dimension to be 50 centimeters.
Minimum integer
Anchor link to section titled "Minimum integer"The following example validates a setting for the minimum integer number to be nine.
Maximum integer
Anchor link to section titled "Maximum integer"The following example validates a setting for the maximum integer number to be 15.
Minimum decimal
Anchor link to section titled "Minimum decimal"The following example validates a setting for the minimum decimal number to be 0.5.
Maximum decimal
Anchor link to section titled "Maximum decimal"The following example validates a setting for the maximum decimal number to be 1.99.
Metaobject definition
Anchor link to section titled "Metaobject definition"The following example validates a setting for the metaobject definition that a reference must point to.
Multiple metaobject definitions
Anchor link to section titled "Multiple metaobject definitions"The following example validates a setting for the permitted metaobject definitions that can be referred to.
JSON schema
Anchor link to section titled "JSON schema"The following example validates a setting for the permitted JSON format.
- Learn how to manage metafield definitions using the GraphQL Admin API.
- Learn how to manage validation options using the GraphQL Admin API.