> ## Documentation Index
> Fetch the complete documentation index at: https://docs.clinia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Basics

> Understand the core validation rules available on Clinia profiles and relationship definitions

Clinia's [profiles](/explanation/data-model/profiles-relationships) and relationship definitions let you attach validation rules to every property. These rules complement the built-in type validators described in the [base data types](/explanation/data-types/base-types) and [Clinia complex types](/explanation/data-types/clinia-types) pages.

## Rule catalog

The `rules` array accepts multiple validation criteria:

| Validation Rule           | Format                        | Data Types                                       |
| :------------------------ | :---------------------------- | :----------------------------------------------- |
| `required`                | `boolean` (`true` or `false`) | All fields (including arrays and custom objects) |
| `min` & `max` (on value)  | `integer` or `decimal`        | Numeric data types                               |
| `min` & `max` (on length) | `integer`                     | String-based types or arrays                     |
| `enum`                    | Must match property type      | Numeric or string-based types                    |
| `pattern`                 | Regex string                  | String-based types                               |

Rules are evaluated in order. You can mix multiple constraints within the same property to achieve stricter contracts.

## Required fields

Marking a property as required enforces that the key must be present and not `null`:

```json {collectForTests=requiredField} theme={null}
{
  "properties": {
    "propertyName": {
      "type": "symbol",
      "rules": [
        {
          "required": true
        }
      ]
    }
  }
}
```

## Numeric data types

`integer` and `decimal` properties can enforce value ranges or enumerations:

```json {collectForTests=numericRules} theme={null}
{
  "properties": {
    "age": {
      "type": "integer",
      "rules": [
        {
          "required": true,
          "min": 18,
          "max": 120
        }
      ]
    },
    "taxRate": {
      "type": "decimal",
      "rules": [
        {
          "enum": [10.5, 12.2, 15.05]
        }
      ]
    }
  }
}
```

## String data types

String-based types (`symbol`, `code`, `markdown`, `uri`, `url`, `xhtml`) can combine length, enumeration, and pattern rules:

```json {collectForTests=stringRules} theme={null}
{
  "properties": {
    "comment": {
      "type": "symbol",
      "rules": [
        {
          "min": 5,
          "max": 120
        }
      ]
    },
    "gender": {
      "type": "code",
      "rules": [
        {
          "enum": ["male", "female", "non-binary"]
        }
      ]
    },
    "email": {
      "type": "symbol",
      "rules": [
        {
          "pattern": "^[\\w\\-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$"
        }
      ]
    }
  }
}
```

<Note>
  Clinia evaluates regular expressions using the ECMAScript flavor. Escape backslashes accordingly: `^[\\w\\-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$`.
</Note>

## Arrays

You can constrain both the array itself and its items:

```json {collectForTests=arrayRules} theme={null}
{
  "properties": {
    "phones": {
      "type": "array",
      "rules": [
        {
          "required": true,
          "min": 2,
          "max": 10
        }
      ],
      "items": {
        "type": "contactpoint",
        "properties": {
          "value": {
            "rules": [
              {
                "required": true
              }
            ]
          }
        }
      }
    }
  }
}
```

* `required` forces the array to be present (it can still be empty).
* `min`/`max` target the number of elements.
* Nested rules apply to every item in the array.

## Objects and complex types

Object properties (custom `object` types or Clinia complex types like `address`, `contactpoint`) only accept `required` at the top level. To validate sub-fields, apply rules directly on nested properties:

```json {collectForTests=nestedObjectCondition} theme={null}
{
  "properties": {
    "address": {
      "type": "address",
      "rules": [{ "required": true }],
      "properties": {
        "city": {
          "rules": [
            {
              "pattern": "^[A-Za-z ]+$",
              "required": true
            }
          ]
        }
      }
    }
  }
}
```

***

Next steps:

* Dive into [advanced validation](/explanation/field-validation/advanced) to apply conditional logic and cardinality.
* Explore [vocabulary binding](/explanation/field-validation/vocabulary) to enforce controlled terminology.
