Constraints
The following constraints may be applied to attributes of the string data type using the /entityType.setAttributeConstraints API.
Constraint | Description |
---|---|
alphabetic | Data may only contain characters A–Z. |
alphanumeric | Data may contain characters A–Z and 0–9. |
unicode-letters | Data may only contain characters encoded using the Unicode standard. |
unicode-printable | Data may only contain Unicode-encoded characters that can be printed to the screen in HTML. The excluded characters are: u0000–u001F, u007F–u009F, \n, \t, and \r. Note that the unicode-printable constraint only works with characters released as part of Unicode 7.0 or earlier; see this article for more information. |
email-address | Data must contain an @ symbol and top level domain suffix, such as .com. |
length | Used only with attributes of type string. Defines the number of characters allowed. By default, string length must be specified for the attribute to be indexed. |
required | Data must contain a non-null value. |
unique | Data must be globally unique across all entities in an entityType. |
locally-unique | Data must be locally unique across plurals within a single entity. |
When added to an attribute, constraints are applied only to data saved to user records after the constraint is applied. The exceptions to this rule are the unique and locally-unique constraints, which apply retroactively to data already collected. If existing data violates the constraint, adding the rule will result in an error. Error responses are explained in detail in the Error Codes topic.
Constraints set on a schema attribute will apply globally to all records. If you need to apply different constraints or validations on data collected at different sites or properties, the Configuration API will allow you to apply those in the flow configuration layer.
Features
The following features may be applied to attributes of the string data type. These features may only be applied by the Akamai team.
Feature | Description |
---|---|
primary-key | Makes the attribute a primary key for the plural or entity type it exists in, providing the ability to target a specific record in a plural in API calls without knowing the actual identifier for that record. Requires both required and either unique or locally-unique constraints. |
query | Adds an index to an attribute to optimize the performance of entity.find API calls. |
Data Validation Rules
The following data validation rules may be applied to attributes using the entityType.addRule API. The table below notes which attribute type each rule may be applied to and what type of argument each rule will accept, if any. Filters that transform input are applied before filters that validate input.
Important. Regular expressions work only when used with single-byte characters. At this point in time, regular expressions cannot be used with Unicode characters.
Rule | Description | Transforms Input? | Attribute Type | Argument Type |
---|---|---|---|---|
match | Data must contain a match from a POSIX-style regular expression. | no | string | string |
match-all | Data must completely match a POSIX-style regular expression. | no | string | string |
min-length | Data must be less than or equal to the argument supplied. | no | string | integer |
max-length | Data must be greater than or equal to the argument supplied. | no | string | integer |
less-than | Data must be less than the argument supplied. | no | integer | number |
greater-than | Data must be greater than the argument supplied. | no | integer | number |
required | Data must contain a non-null value. | no | any | none |
min-age | The date submitted must be at least n years ago. | no | date | integer |
default | Data will be pre-populated with the argument supplied. | yes | any | integer or string |
ignore-update | yes | any | none | |
truncate | Stores only the first n characters of the value submitted. | yes | string | integer |
to-lower | Converts a string value to lower case. | yes | string | none |
to-upper | Converts a string value to upper case. | yes | string | none |
and | Combines a list of filters and fails if one of the filters fails. | maybe | array of rules | array of strings and/or objects |
or | Combines a list of filters and fails if all of the filters failed. | maybe | array of rules | array of strings and/or objects |
not | Turns a failed filter result into a successful filter result. | maybe | rule | string or object |
When added to an attribute, rules are applied only to data saved to user records after the rules are applied. When a rule is violated, a 360 (constraint_violation) error is returned. Error responses are explained in detail in the Error Codes topic.
Rules set on a schema attribute will apply globally to all records. If you need to apply different constraints or validations on data collected at different sites or properties, the Configuration API will allow you to apply those in the flow configuration layer.
Rule Definition Examples
Values are truncated to 100 characters if their length is over 100 and converted to lower case:
{
"and": [
{"truncate": 100}
,"to-lower"
]
}
Values are rejected if they are less than six characters long or contain any 3s or fs:
{
"and": [
{"min-length": 6},
{"not": {
"match":"[3f]"
}
}
]
}
Sets a minimum age of 16:
{
"and":[
{
"min-age":16
},
"required"
]
}