Skip to main content

Constraints

Constraints define set of rules that are applied for validation of the Attribute content as input. The Attribute content is validated when the Attribute is created or updated. Validation is controlled consistently by the platform and ensures that the Attribute content is valid and can be used for further processing.

Attributes that support constraints

For more information about Attribute types that support constraints, see Attributes.

Constraint properties

Every constraint is extended from the base class of BaseAttributeConstraint which is abstracted from AttributeConstraint.

The constraint has the following properties defined and inherited from the BaseAttributeConstraint:

PropertyTypeShort descriptionRequired
descriptionstringDescription of the constraintNo
errorMessagestringError message to be displayed when the constraint is violatedNo
typeAttributeConstraintTypeType of the constraintYes
dataAttributeConstraintData to be used for the constraintYes

Supported constraints types

Supported constraint types are defined in the AttributeConstraintType. The following content types are available and supported:

AttributeConstraintTypeClassData
REGEXPRegexpAttributeConstraintstring
RANGERangeAttributeConstraintRangeAttributeConstraintData
DATETIMEDateTimeAttributeConstraintDateTimeAttributeConstraintData

Constraint type description and samples

RegExpAttributeConstraint

Use this constraint when the content needs to be validated against a regular expression.

{
"description": "Alphanumeric Regex Constraint",
"errorMessage": "Only alphanumeric characters are allowed",
"type": "RegExp",
"data": "^[a-zA-Z0-9]*$"
}

RangeAttributeConstraint

Use this constraint when the content needs to be validated against a range of integers.

{
"description": "Range Constraint",
"errorMessage": "Value should be between 1 and 10",
"type": "range",
"data": {
"from": 1,
"to": 10
}
}

DateTimeAttributeConstraint

Use this constraint when you need to validate date and time.

{
"description": "Date Time Constraint",
"errorMessage": "Value should be between 1 and 10",
"type": "datetime",
"data": {
"from": "2020-01-01T00:00:00.000Z",
"to": "2020-12-31T00:00:00.000Z"
}
}

Constraint model

The following diagram represents the constraint model inherited from the AttributeConstraint. Details can be found in the CZERTAINLY Interfaces repository.