# Regex Constrains within the attributes of entities and relations

**URL:** https://forum.typedb.com/t/regex-constrains-within-the-attributes-of-entities-and-relations/495
**Category:** TypeQL
**Created:** [24 May 2024 17:58 UTC](https://forum.typedb.com/t/regex-constrains-within-the-attributes-of-entities-and-relations/495 "2024-05-24T17:58:13Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![c-lare](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@c-lare](https://forum.typedb.com/u/c-lare)
#### Post date: [24 May 2024 17:58 UTC](https://forum.typedb.com/t/regex-constrains-within-the-attributes-of-entities-and-relations/495/1 "2024-05-24T17:58:13Z")

</div>

Hi all, according to the documentation, regex constraints can be applied within the owning definition of entities and relations.

Documentation Example:

```auto
define
full-name sub attribute, value string;
office-location sub attribute, value string;
id sub attribute, value string;
email sub id;
employee-id sub id;
user sub entity,
    owns full-name,
    owns email @unique, regex "^(.+)@(\\S+)$";
employee sub user,
    owns employee-id @key,
    owns office-location, regex "^(London|Paris|Dublin)$";

```

However, when I execute this define query:

```auto
define product sub entity, owns price, regex "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z]{2,}$", owns size, owns identifier @key, plays selling:sold;

```

I get this error:

```auto
[TYR01] Invalid Type Read: Invalid concept conversion from 'product' to 'AttributeType'.

```

which I interpret as “Regex constraints should be within the attribute definition” but maybe I just have an error in my define query?

I would highly appreciate your help! 🙂

---

<div class="post-metadata">

### Author: ![jameswhiteside](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.typedb.com/jameswhiteside/32/94_2.png) [@jameswhiteside](https://forum.typedb.com/u/jameswhiteside)
#### Post date: [31 May 2024 10:51 UTC](https://forum.typedb.com/t/regex-constrains-within-the-attributes-of-entities-and-relations/495/2 "2024-05-31T10:51:42Z")

</div>

Hi, the error is correctly thrown and your assumption as to its nature is also correct. The `regex` constraint should be placed directly on the attributes as a statement, for example:

```auto
office-location regex "^(London|Paris|Dublin)$";

```

It applies to all instances of the attribute type, regardless of the type of the owner.

Could you please let us know where you found that example? We’ll make sure to correct it.

---

<div class="post-metadata">

### Author: ![c-lare](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@c-lare](https://forum.typedb.com/u/c-lare)
#### Post date: [1 June 2024 06:05 UTC](https://forum.typedb.com/t/regex-constrains-within-the-attributes-of-entities-and-relations/495/3 "2024-06-01T06:05:20Z")

</div>

Hi @jameswhiteside ,

Thanks for your answer. Makes also very much sense to define it globally for the attribute as such.

I found the example here under “Attribute Constraints”

> **[TypeDB Features](https://typedb.com/features)**
>
> Meet TypeDB and TypeQL: a polymorphic database with a conceptual data model, a strong subtyping system, a symbolic reasoning engine, and a beautiful and elegant type-theoretic language.
