@regex
annotation
The @regex
annotation is used
to specify a regex pattern for permitted values of attributes.
Syntax
<type label> value <value type> @regex("<regular expression>");
<type label> owns <attribute type label> @regex("<regular expression>");
The @regex
annotation can be defined for either an attribute type’s value type or an ownership.
The @range
annotation accepts a single string argument containing a regular expression.
Usage
The @regex
annotation adds a constraint on values of attributes of a given attribute type to be valid strings according to the regular expression.
When defined for an attribute type’s value type, the annotation creates a constraint for any attribute of this attribute type.
define
attribute email value string @regex("^.*@\w+\.\w+$");
When defined for an ownership, the annotation creates a constraint for any attribute of this attribute type owned by the owner type.
In the following example, an instance of the phone
type can contain any string
value, but a user
can have (has
) only the phone
s with the suitable values.
define
entity user owns phone @regex("^\d{10,15}$");
attribute phone value string;
Subtyping
The regex
constraint put on an attribute types' value type is inherited.
This means that values of all subtypes of a constrained type are also constrained, and it cannot be changed.
A subtype can introduce another regex
constraint to combine it with the inherited one and create a subset of allowed values based on the intersection of the specified regular expressions.
Subtyping for ownerships
The regex
constraint put on an ownership should be respected by all the sub attribute types owned by this owner. This way, any instance of any subtype of the phone
owned by any instance of any subtype of the user
should comply to the defined regex
.
Ownerships of these subtypes can have their own regex
constraints, and they will be respected similarly down the inheritance line.
Limitations
Is only compatible with string
value type.