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:
Validation option | Description | Supported types | Example |
---|---|---|---|
Minimum length | A validation for setting the minimum length of a text value. Example use cases:
|
|
validations: |
Maximum length | A validation for setting the maximum length of a text value. Example use cases:
|
|
validations: |
Regular expression | A validation for setting a regular expression. Shopify supports RE2. Example use cases:
|
|
validations: |
Allowed domains | A list of allowed domains. Example use cases:
|
url |
validations: |
Choices | A list of up to 128 predefined options that limits the values allowed for the metafield. Example use cases:
|
single_line_text_field |
validations: |
File type options | A list of file type options. Leaving this empty allows all files, regardless of type. Valid values: Image , Video .Example use cases:
|
file_reference |
validations: |
Maximum precision | Sets the maximum number of decimal places to store for a decimal number. Example use cases:
|
number_decimal |
validations: |
Minimum date | A validation for setting the minimum date in ISO 8601 format. Example use case: The date field for an expiry date or a product release needs to be after a specific date. |
date |
validations: |
Maximum date | A validation for setting the maximum date in ISO 8601 format. Example use case: The date for future product availability can't be later than a certain date. |
date |
validations: |
Minimum datetime | A validation for setting the minimum date and time in ISO 8601 format. Example use case: A product release occurs on a specific date at midnight, and the product won't display before that date and time. |
date_time |
validations: |
Maximum datetime | A validation for setting the maximum date and time in ISO 8601 format. Example use case: A customer loyalty reward expires on a specific date and time. The reward can't be used after that date and time. |
date_time |
validations: |
Minimum weight | A validation for setting the minimum weight. Example use case: A bundled product weight field needs to have a maximum allowed weight. |
weight |
validations: |
Maximum weight | A validation for setting the maximum weight. Example use case: An order requires a minimum weight for shipping. |
weight |
validations: |
Minimum volume | A validation for setting the minimum volume. Example use cases:
|
volume |
validations: |
Maximum volume | A validation for setting the maximum volume. Example use cases:
|
volume |
validations: |
Minimum dimension | A validation for setting the minimum dimension. Example use case: A product needs to have a minimum length, width, or height. |
dimension |
validations: |
Maximum dimension | A validation for setting the maximum dimension. Example use case: A product needs to have a minimum length, width, or height. |
dimension |
validations: |
Minimum integer | A validation for setting the minimum integer number. Example use case: A product number needs to be within a specific range of numbers, so you can use both the minimum and maximum integer validation to set the range. |
number_integer |
validations: |
Maximum integer | A validation for setting the maximum integer number. Example use case: A product number needs to be within a specific range of numbers, so you use both the minimum and maximum integer validation to set the range. |
number_integer |
validations: |
Minimum decimal | A validation for setting the minimum decimal number. Example use case: A product version field needs to accept a version greater than a specific decimal number, such as 0.5 . |
number_decimal |
validations: |
Maximum decimal | A validation for setting the maximum decimal number. Example use case: A product version field needs to accept a version number less than a specific decimal numbner, such as 1.99 . |
number_decimal |
validations: |
Metaobject definition | A validation for setting the metaobject definition a reference must point to. Example use case: A product refers to a "Designer" metaobject. |
|
validations: |
Multiple metaobject definitions | A validation for setting the permitted metaobject definitions that can be referred to. Example use case:
|
|
validations: |
- Learn how to manage metafield definitions using the GraphQL Admin API.
- Learn how to manage validation options using the GraphQL Admin API.