The Plugin.Validation.PolicySet

Abstract

Describes and lists a group of default validation policies that the Commerce Engine uses to validate input values entered in the Business Tools or via API requests.

The Plugin.Validation.PolicySet.json file defines a group of validation policies that the Commerce Engine enforces on some of the configuration input values entered using the Business Tools or via API calls.

The validation policies can apply to Commerce entity properties or to entity components properties.

In the Commerce Engine SDK.*.zip package, you can see the default policy set JSON file provided in the sample Sitecore.Commerce.Engine solution. The path to the default policy set file is:

wwwroot\data\Environments\Plugin.Validation.PolicySet-1.0.0.json

Example validation policies

The following shows an example of the validation policies applied by default to the Customer entity properties:

"$type": "Sitecore.Commerce.Core.ValidationPolicy, Sitecore.Commerce.Core",
        "TypeFullName": "Sitecore.Commerce.Plugin.Customers.Customer",
        "Models": {
          "$type": "System.Collections.Generic.List`1[[Sitecore.Commerce.Core.Model, Sitecore.Commerce.Core]], mscorlib",
          "$values": [
            {
              "$type": "Sitecore.Commerce.Core.ValidationAttributes, Sitecore.Commerce.Core",
              "Name": "AccountNumber",
              "MaxLength": 100,
              "MinLength": 1
            },
            {
              "$type": "Sitecore.Commerce.Core.ValidationAttributes, Sitecore.Commerce.Core",
              "Name": "AccountStatus",
              "MaxLength": 100,
              "MinLength": 1
            },
            {
              "$type": "Sitecore.Commerce.Core.ValidationAttributes, Sitecore.Commerce.Core",
              "Name": "LoginName",
              "MaxLength": 100,
              "MinLength": 1
            },
            {
              "$type": "Sitecore.Commerce.Core.ValidationAttributes, Sitecore.Commerce.Core",
              "Name": "Email",
              "MaxLength": 100,
              "MinLength": 1,
              "RegexValidator": "^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$",
              "RegexValidatorErrorCode": "Customer_EmailValidationError"
            },
            {
              "$type": "Sitecore.Commerce.Core.ValidationAttributes, Sitecore.Commerce.Core",
              "Name": "Password",
              "MaxLength": 100
            },
            {
              "$type": "Sitecore.Commerce.Core.ValidationAttributes, Sitecore.Commerce.Core",
              "Name": "FirstName",
              "MaxLength": 100
            },
            {
              "$type": "Sitecore.Commerce.Core.ValidationAttributes, Sitecore.Commerce.Core",
              "Name": "LastName",
              "MaxLength": 100
            },
            {
              "$type": "Sitecore.Commerce.Core.ValidationAttributes, Sitecore.Commerce.Core",
              "Name": "Language",
              "MaxLength": 100
            }
          ]
        }
      },

Validation policy properties

The Sitecore.Commerce.Core.ValidationAttributes model defines the validation properties that the Commerce Engine supports to define validation policies.

You can use any of these properties to define your custom validation policies.

Note

Some of these properties are not currently used in the default validation policy set.

Property

Description

MinLength                                      

The minimum number of characters required in a valid property value.

MaxLength

The maximum number of characters allowed in a valid property value.

MinValue

An integer representing the minimum property value.

MaxValue

An integer representing the maximum property value.

StartDate

The start date in a date range.

EndDate

The end date in a date range.

RegexValidator

The regular expressions against which to compare a sequences of input characters. For example, the Customer "email" property value is validated against the following regular expression by default: ("^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$")

RegexValidatorErrorCode

The error code corresponding to a defined commerce term value to display as an error message.

For example, the value Customer_EmailValidationError is a pre-defined commerce term that has the following display value: "Email is not valid."

CustomValidator

A custom validator.